fix(cli/js/web/url): Support UNC paths on Windows (#6418)

This commit is contained in:
Nayeem Rahman 2020-06-26 13:34:17 +01:00 committed by GitHub
parent 175867ab76
commit ed0b1d4627
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 33 deletions

View file

@ -62,12 +62,15 @@ function parse(url: string, isBase = true): URLParts | undefined {
parts.password = "";
[parts.hostname, restUrl] = takePattern(restUrl, /^[/\\]{2}([^/\\?#]*)/);
parts.port = "";
if (build.os == "windows" && parts.hostname == "") {
// UNC paths. e.g. "\\\\localhost\\foo\\bar" on Windows should be
// representable as `new URL("file:////localhost/foo/bar")` which is
// equivalent to: `new URL("file://localhost/foo/bar")`.
[parts.hostname, restUrl] = takePattern(restUrl, /^[/\\]{2,}([^/\\?#]*)/);
}
} else if (specialSchemes.includes(parts.protocol)) {
let restAuthority;
[restAuthority, restUrl] = takePattern(
restUrl,
/^[/\\]{2}[/\\]*([^/\\?#]+)/
);
[restAuthority, restUrl] = takePattern(restUrl, /^[/\\]{2,}([^/\\?#]+)/);
if (isBase && restAuthority == "") {
return undefined;
}