From f16aeec2396f78cc3cedcaafa5d58899408ffb99 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 6 Sep 2015 17:43:29 +0100 Subject: Allow localhost in file:/// URIs --- lib/docx/files.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/docx/files.js b/lib/docx/files.js index e25d9cc..4e3a820 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -1,4 +1,5 @@ var fs = require("fs"); +var url = require("url"); var promises = require("../promises"); @@ -20,15 +21,11 @@ function Files() { var readFile = promises.promisify(fs.readFile.bind(fs)); -function uriToPath(uri) { - var fileUriPrefix = "file:///"; - if (startsWith(uri, fileUriPrefix)) { - return decodeURIComponent(uri.slice(fileUriPrefix.length - 1)); +function uriToPath(uriString) { + var uri = url.parse(uriString); + if (uri.protocol === "file:" && (!uri.host || uri.host === "localhost")) { + return decodeURIComponent(uri.path); } else { - throw new Error("Could not convert URI to path: " + uri); + throw new Error("Could not convert URI to path: " + uriString); } } - -function startsWith(string, search) { - return string.indexOf(search) === 0; -} -- cgit v1.2.3