Resolve protocol-relative URLs outside of document context

by defaulting to HTTP
This commit is contained in:
Aurimas Vinckevicius 2014-11-20 06:55:22 -06:00
parent 6e43942385
commit 325f0618d6

View file

@ -1208,16 +1208,22 @@ Zotero.Translate.Base.prototype = {
} else { } else {
resolved = url; resolved = url;
} }
} else if(Zotero.isFx) { } else if(Zotero.isFx && this.location) {
resolved = Components.classes["@mozilla.org/network/io-service;1"]. resolved = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService). getService(Components.interfaces.nsIIOService).
newURI(this.location, "", null).resolve(url); newURI(this.location, "", null).resolve(url);
} else if(Zotero.isNode) { } else if(Zotero.isNode && this.location) {
resolved = require('url').resolve(this.location, url); resolved = require('url').resolve(this.location, url);
} else if (this.document) {
var a = this.document.createElement('a');
a.href = url;
resolved = a.href;
} else if (url.indexOf('//') == 0) {
// Protocol-relative URL with no associated web page
// Use HTTP by default
resolved = 'http:' + url;
} else { } else {
var a = document.createElement('a'); throw new Error('Cannot resolve relative URL without an associated web page: ' + url);
a.href = url;
resolved = a.href;
} }
/*var m = hostPortRe.exec(resolved); /*var m = hostPortRe.exec(resolved);