From 629c5ecab28c3d3557bf3fb7998c54db6c0f8f04 Mon Sep 17 00:00:00 2001
From: Abe Jellinek <jellinek@berkeley.edu>
Date: Tue, 16 Jul 2024 11:15:12 -0400
Subject: [PATCH] Find Full Text: Support Atypon (#4397)

Don't remove all query strings when normalizing URLs - keep 'download'
so that Atypon PDFs/EPUBs resolve correctly.
---
 chrome/content/zotero/xpcom/attachments.js | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js
index 8c113d74a5..b16487b324 100644
--- a/chrome/content/zotero/xpcom/attachments.js
+++ b/chrome/content/zotero/xpcom/attachments.js
@@ -1883,7 +1883,15 @@ Zotero.Attachments = new function () {
 		// Don't try the same normalized URL more than once
 		var triedURLs = new Set();
 		function normalizeURL(url) {
-			return url.replace(/\?.*/, '');
+			url = new URL(url);
+			for (let param of Array.from(url.searchParams.keys())) {
+				// Keep 'download' param for Atypon
+				if (param !== 'download') {
+					url.searchParams.delete(param);
+				}
+			}
+			url.searchParams.sort();
+			return url.toString();
 		}
 		function isTriedURL(url) {
 			return triedURLs.has(normalizeURL(url));