From f98ab3b0a6f4a1c1721034e50f4fd618180c945f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Mon, 21 Nov 2022 11:51:18 +0200 Subject: [PATCH] Import URL from XPCOM code instead of relying on window for Proxy code Also fix other failing proxy tests. Closes #2928 --- chrome/content/zotero/xpcom/proxy.js | 16 ++++------------ test/tests/proxyTest.js | 8 ++++---- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/chrome/content/zotero/xpcom/proxy.js b/chrome/content/zotero/xpcom/proxy.js index 2cafe366bd..074090251e 100644 --- a/chrome/content/zotero/xpcom/proxy.js +++ b/chrome/content/zotero/xpcom/proxy.js @@ -23,6 +23,8 @@ ***** END LICENSE BLOCK ***** */ +Components.utils.importGlobalProperties(["URL"]); + /** * A singleton to handle URL rewriting proxies * @namespace @@ -139,12 +141,7 @@ Zotero.Proxies = new function() { */ this.proxyToProper = function(url, onlyReturnIfProxied) { // make sure url has a trailing slash - if (typeof URL === 'undefined') { - url = new (Services.wm.getMostRecentWindow("navigator:browser")).URL(url).href; - } - else { - url = new URL(url).href; - } + url = new URL(url).href; for (let proxy of Zotero.Proxies.proxies) { if(proxy.regexp) { var m = proxy.regexp.exec(url); @@ -185,12 +182,7 @@ Zotero.Proxies = new function() { */ this.getPotentialProxies = function(url) { // make sure url has a trailing slash - if (typeof URL === 'undefined') { - url = new (Services.wm.getMostRecentWindow("navigator:browser")).URL(url).href; - } - else { - url = new URL(url).href; - } + url = new URL(url).href; var urlToProxy = {}; // If it's a known proxied URL just return it if (Zotero.Proxies.transparent) { diff --git a/test/tests/proxyTest.js b/test/tests/proxyTest.js index 6cfc4d75a9..af07821487 100644 --- a/test/tests/proxyTest.js +++ b/test/tests/proxyTest.js @@ -11,20 +11,20 @@ describe("Zotero.Proxies", function(){ }); it("should return the provided url and deproxied url", function() { - let url = "https://www.example.com.proxy.example.com"; + let url = "https://www.example.com.proxy.example.com/"; let proxies = Zotero.Proxies.getPotentialProxies(url); let expectedProxies = {}; expectedProxies[url] = null; - expectedProxies["https://www.example.com"] = {scheme: "https://%h.proxy.example.com/%p"}; + expectedProxies["https://www.example.com/"] = {scheme: "https://%h.proxy.example.com/%p"}; assert.deepEqual(proxies, expectedProxies); }); it("should return the provided url and deproxied url with replaced hyphens", function() { - let url = "https://www-example-com.proxy.example.com"; + let url = "https://www-example-com.proxy.example.com/"; let proxies = Zotero.Proxies.getPotentialProxies(url); let expectedProxies = {}; expectedProxies[url] = null; - expectedProxies["https://www.example.com"] = {scheme: "https://%h.proxy.example.com/%p"}; + expectedProxies["https://www.example.com/"] = {scheme: "https://%h.proxy.example.com/%p"}; assert.deepEqual(proxies, expectedProxies); }); });