diff options
author | River <22485304+actual-size@users.noreply.github.com> | 2020-06-18 20:10:07 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-18 06:10:07 -0400 |
commit | 2a5af8b36b233b6330997b2262a45a23034d719d (patch) | |
tree | fea75b0ab622fefccc4d335bac21282fb1bb3bad /cli/js/util.ts | |
parent | eea3223ade98a13ef4811e7d713df618375201d1 (diff) |
fix: decode path properly on win32 (#6351)
Diffstat (limited to 'cli/js/util.ts')
-rw-r--r-- | cli/js/util.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cli/js/util.ts b/cli/js/util.ts index c50a4cdcb..a67dec595 100644 --- a/cli/js/util.ts +++ b/cli/js/util.ts @@ -82,19 +82,21 @@ export function immutableDefine( } function pathFromURLWin32(url: URL): string { - if (url.hostname !== "") { + const hostname = url.hostname; + const pathname = decodeURIComponent(url.pathname.replace(/\//g, "\\")); + + if (hostname !== "") { //TODO(actual-size) Node adds a punycode decoding step, we should consider adding this - return `\\\\${url.hostname}${url.pathname}`; + return `\\\\${hostname}${pathname}`; } - const validPath = /^\/(?<driveLetter>[A-Za-z]):\//; - const matches = validPath.exec(url.pathname); + const validPath = /^\\(?<driveLetter>[A-Za-z]):\\/; + const matches = validPath.exec(pathname); if (!matches?.groups?.driveLetter) { throw new TypeError("A URL with the file schema must be absolute."); } - const pathname = url.pathname.replace(/\//g, "\\"); // we don't want a leading slash on an absolute path in Windows return pathname.slice(1); } |