diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-07-30 23:37:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 18:37:26 -0400 |
commit | 6e7208bec2911ac0d1729f334fc90bc50b8f9203 (patch) | |
tree | 1361d123ca43e66bb0725295b59a1b5075108517 /cli/rt/06_util.js | |
parent | 0da4779b178a0c97925c1ef5589d0f24a37f4501 (diff) |
fix(cli/rt): Fix file URL to path conversion on Windows (#6920)
Diffstat (limited to 'cli/rt/06_util.js')
-rw-r--r-- | cli/rt/06_util.js | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/cli/rt/06_util.js b/cli/rt/06_util.js index 086275bd8..3570cb1fa 100644 --- a/cli/rt/06_util.js +++ b/cli/rt/06_util.js @@ -64,23 +64,18 @@ } function pathFromURLWin32(url) { - 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 `\\\\${hostname}${pathname}`; + let path = decodeURIComponent( + url.pathname + .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/") + .replace(/\//g, "\\"), + ); + if (url.hostname != "") { + // Note: The `URL` implementation guarantees that the drive letter and + // hostname are mutually exclusive. Otherwise it would not have been valid + // to append the hostname and path like this. + path = `\\\\${url.hostname}${path}`; } - - 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."); - } - - // we don't want a leading slash on an absolute path in Windows - return pathname.slice(1); + return path; } function pathFromURLPosix(url) { |