From d05a33b0bd26255f7c8731d0f3c610eb69484acd Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sun, 21 Sep 2008 12:48:51 +0000 Subject: [PATCH] fix Bug#: 19949 - file:// URL loading is broken --- content/io.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/content/io.js b/content/io.js index 9b00cca9..6851ff28 100644 --- a/content/io.js +++ b/content/io.js @@ -327,7 +327,7 @@ liberator.IO = function () //{{{ expandPath: function (path) { - // TODO: proper pathname separator translation like Vim + // TODO: proper pathname separator translation like Vim - this should be done elsewhere if (WINDOWS) path = path.replace("/", "\\", "g"); @@ -452,17 +452,25 @@ liberator.IO = function () //{{{ // also expands relative paths getFile: function (path) { - var file = Components.classes["@mozilla.org/file/local;1"] + let file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); + let protocolHandler = Components.classes["@mozilla.org/network/protocol;1?name=file"] + .createInstance(Components.interfaces.nsIFileProtocolHandler); - // convert relative to absolute pathname - path = ioManager.expandPath(path); - if (!/^(file:|[a-zA-Z]:|\/)/.test(path)) // starts not with either /, C: or file: - path = ioManager.getCurrentDirectory() + (WINDOWS ? "\\" : "/") + path; // TODO: for now homedir, later relative to current dir? + if (/file:\/\//.test(path)) + { + file = protocolHandler.getFileFromURLSpec(path); + } else - path = path.replace(/^file:(\/\/)?/, ""); + { + let expandedPath = ioManager.expandPath(path); + + if (!/^([a-zA-Z]:|\/)/.test(expandedPath)) // doesn't start with /, C: + expandedPath = ioManager.getCurrentDirectory() + (WINDOWS ? "\\" : "/") + expandedPath; + + file.initWithPath(expandedPath); + } - file.initWithPath(path); return file; },