diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-09-06 17:48:55 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-09-06 17:48:55 +0100 |
| commit | ced42637087b386df99cfd017262afad03b809ce (patch) | |
| tree | 17d63ea592c875464e8001076b38e9ff66d2657c /lib | |
| parent | f16aeec2396f78cc3cedcaafa5d58899408ffb99 (diff) | |
Parse file URIs on Windows
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/files.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/docx/files.js b/lib/docx/files.js index 4e3a820..e17bd45 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -1,5 +1,6 @@ var fs = require("fs"); var url = require("url"); +var os = require("os"); var promises = require("../promises"); @@ -21,10 +22,19 @@ function Files() { var readFile = promises.promisify(fs.readFile.bind(fs)); -function uriToPath(uriString) { +function uriToPath(uriString, platform) { + if (!platform) { + platform = os.platform(); + } + var uri = url.parse(uriString); if (uri.protocol === "file:" && (!uri.host || uri.host === "localhost")) { - return decodeURIComponent(uri.path); + var path = decodeURIComponent(uri.path); + if (platform === "win32" && /^\/[a-z]:/i.test(path)) { + return path.slice(1); + } else { + return path; + } } else { throw new Error("Could not convert URI to path: " + uriString); } |
