From 6a0a91d832419430adf13d64c4b70690228634d7 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Sat, 2 Apr 2016 12:23:06 +0200 Subject: [PATCH] Unescape pathname from url when loading from local filesystem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a path contains a space it will be escaped to ’%20’. When loading from local filesystem it has to be converted back to a space to get the correct path. --- lib/XMLHttpRequest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/XMLHttpRequest.js b/lib/XMLHttpRequest.js index 3c23907..80b58c1 100644 --- a/lib/XMLHttpRequest.js +++ b/lib/XMLHttpRequest.js @@ -322,7 +322,7 @@ function XMLHttpRequest(opts) { } if (settings.async) { - fs.readFile(url.pathname, 'utf8', function(error, data) { + fs.readFile(unescape(url.pathname), 'utf8', function(error, data) { if (error) { self.handleError(error); } else { @@ -333,7 +333,7 @@ function XMLHttpRequest(opts) { }); } else { try { - this.responseText = fs.readFileSync(url.pathname, 'utf8'); + this.responseText = fs.readFileSync(unescape(url.pathname), 'utf8'); this.status = 200; setState(self.DONE); } catch(e) {