Utilities.Translate.resolveURL() tweaks
- Use `new URL()`, available in all modern environments, instead of various other methods. In addition to being consistent and simple, this allows setting the base URL explicitly, regardless of the environment. - Default protocol-relative URLs to 'https' if no document location (though I'm not sure if that ever happens)
This commit is contained in:
parent
8214c85bee
commit
c0b6712923
1 changed files with 8 additions and 16 deletions
|
@ -1395,22 +1395,14 @@ Zotero.Translate.Base.prototype = {
|
|||
var m = url.match(hostPortRe),
|
||||
resolved;
|
||||
if (!m) {
|
||||
// Convert relative URLs to absolute
|
||||
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 && this.location) {
|
||||
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 {
|
||||
if (this.location) {
|
||||
resolved = new URL(url, this.location).toString();
|
||||
}
|
||||
else if (url.startsWith('//')) {
|
||||
// Use HTTPS by default for protocol-relative URL with no associated web page
|
||||
resolved = 'https:' + url;
|
||||
}
|
||||
else {
|
||||
throw new Error('Cannot resolve relative URL without an associated web page: ' + url);
|
||||
}
|
||||
} else if (allowedSchemes.indexOf(m[1].toLowerCase()) == -1) {
|
||||
|
|
Loading…
Reference in a new issue