From d47381512e642c5d981972f455565f3b0f6d1259 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 10 Jul 2011 22:51:22 +0000 Subject: [PATCH] Fix relative URL resolution in Chrome/Safari/Node --- chrome/content/zotero/xpcom/utilities.js | 32 +++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index d6f9668838..11ee4cc33c 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1325,23 +1325,27 @@ Zotero.Utilities.Translate.prototype._convertURL = function(url) { url = this._translate.translator[0].properToProxy(url); } - if(Zotero.isChrome || Zotero.isSafari) { - // this code is sandboxed, so we don't worry - return url; - } else { - if(protocolRe.test(url)) return url; - - // resolve local URL - var resolved = Components.classes["@mozilla.org/network/io-service;1"]. + if(protocolRe.test(url)) return url; + + // resolve local URL + var resolved = ""; + if(Zotero.isFx) { + resolved = Components.classes["@mozilla.org/network/io-service;1"]. getService(Components.interfaces.nsIIOService). newURI(this._translate.location, "", null).resolve(url); - - if(!protocolRe.test(resolved)) { - throw new Error("Invalid URL supplied for HTTP request: "+url); - } - - return resolved; + } else if(Zotero.isChrome || Zotero.isSafari) { + var a = document.createElement('a'); + a.href = url; + resolved = a.href; + } else if(Zotero.isNode) { + resolved = require('url').resolve(this._translate.location, url); } + + if(!protocolRe.test(resolved)) { + throw new Error("Invalid URL supplied for HTTP request: "+url); + } + + return resolved; } Zotero.Utilities.Translate.prototype.__exposedProps__ = {"HTTP":"r"};