Import URL from XPCOM code instead of relying on window for Proxy code
Also fix other failing proxy tests. Closes #2928
This commit is contained in:
parent
b561aff94f
commit
f98ab3b0a6
2 changed files with 8 additions and 16 deletions
|
@ -23,6 +23,8 @@
|
||||||
***** END LICENSE BLOCK *****
|
***** END LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Components.utils.importGlobalProperties(["URL"]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton to handle URL rewriting proxies
|
* A singleton to handle URL rewriting proxies
|
||||||
* @namespace
|
* @namespace
|
||||||
|
@ -139,12 +141,7 @@ Zotero.Proxies = new function() {
|
||||||
*/
|
*/
|
||||||
this.proxyToProper = function(url, onlyReturnIfProxied) {
|
this.proxyToProper = function(url, onlyReturnIfProxied) {
|
||||||
// make sure url has a trailing slash
|
// make sure url has a trailing slash
|
||||||
if (typeof URL === 'undefined') {
|
url = new URL(url).href;
|
||||||
url = new (Services.wm.getMostRecentWindow("navigator:browser")).URL(url).href;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
url = new URL(url).href;
|
|
||||||
}
|
|
||||||
for (let proxy of Zotero.Proxies.proxies) {
|
for (let proxy of Zotero.Proxies.proxies) {
|
||||||
if(proxy.regexp) {
|
if(proxy.regexp) {
|
||||||
var m = proxy.regexp.exec(url);
|
var m = proxy.regexp.exec(url);
|
||||||
|
@ -185,12 +182,7 @@ Zotero.Proxies = new function() {
|
||||||
*/
|
*/
|
||||||
this.getPotentialProxies = function(url) {
|
this.getPotentialProxies = function(url) {
|
||||||
// make sure url has a trailing slash
|
// make sure url has a trailing slash
|
||||||
if (typeof URL === 'undefined') {
|
url = new URL(url).href;
|
||||||
url = new (Services.wm.getMostRecentWindow("navigator:browser")).URL(url).href;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
url = new URL(url).href;
|
|
||||||
}
|
|
||||||
var urlToProxy = {};
|
var urlToProxy = {};
|
||||||
// If it's a known proxied URL just return it
|
// If it's a known proxied URL just return it
|
||||||
if (Zotero.Proxies.transparent) {
|
if (Zotero.Proxies.transparent) {
|
||||||
|
|
|
@ -11,20 +11,20 @@ describe("Zotero.Proxies", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return the provided url and deproxied url", 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 proxies = Zotero.Proxies.getPotentialProxies(url);
|
||||||
let expectedProxies = {};
|
let expectedProxies = {};
|
||||||
expectedProxies[url] = null;
|
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);
|
assert.deepEqual(proxies, expectedProxies);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return the provided url and deproxied url with replaced hyphens", function() {
|
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 proxies = Zotero.Proxies.getPotentialProxies(url);
|
||||||
let expectedProxies = {};
|
let expectedProxies = {};
|
||||||
expectedProxies[url] = null;
|
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);
|
assert.deepEqual(proxies, expectedProxies);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue