Resolve protocol-relative URLs outside of document context
by defaulting to HTTP
This commit is contained in:
parent
6e43942385
commit
325f0618d6
1 changed files with 11 additions and 5 deletions
|
@ -1208,16 +1208,22 @@ Zotero.Translate.Base.prototype = {
|
|||
} else {
|
||||
resolved = url;
|
||||
}
|
||||
} else if(Zotero.isFx) {
|
||||
} else if(Zotero.isFx && this.location) {
|
||||
resolved = Components.classes["@mozilla.org/network/io-service;1"].
|
||||
getService(Components.interfaces.nsIIOService).
|
||||
newURI(this.location, "", null).resolve(url);
|
||||
} else if(Zotero.isNode) {
|
||||
} else if(Zotero.isNode && this.location) {
|
||||
resolved = require('url').resolve(this.location, url);
|
||||
} else {
|
||||
var a = document.createElement('a');
|
||||
} 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 {
|
||||
throw new Error('Cannot resolve relative URL without an associated web page: ' + url);
|
||||
}
|
||||
|
||||
/*var m = hostPortRe.exec(resolved);
|
||||
|
|
Loading…
Reference in a new issue