diff options
Diffstat (limited to 'cli/js/web/url.ts')
-rw-r--r-- | cli/js/web/url.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/cli/js/web/url.ts b/cli/js/web/url.ts index bbe405f85..76aa21919 100644 --- a/cli/js/web/url.ts +++ b/cli/js/web/url.ts @@ -39,7 +39,7 @@ const MAX_PORT = 2 ** 16 - 1; // (LHS). e.g. // takePattern("https://deno.land:80", /^([a-z]+):[/]{2}/) // = ["http", "deno.land:80"] -// takePattern("deno.land:80", /^([^:]+):) +// takePattern("deno.land:80", /^(\[[0-9a-fA-F.:]{2,}\]|[^:]+)/) // = ["deno.land", "80"] function takePattern(string: string, pattern: RegExp): [string, string] { let capture = ""; @@ -80,7 +80,10 @@ function parse(url: string, isBase = true): URLParts | undefined { parts.username = encodeUserinfo(parts.username); [parts.password] = takePattern(restAuthentication, /^:(.*)/); parts.password = encodeUserinfo(parts.password); - [parts.hostname, restAuthority] = takePattern(restAuthority, /^([^:]+)/); + [parts.hostname, restAuthority] = takePattern( + restAuthority, + /^(\[[0-9a-fA-F.:]{2,}\]|[^:]+)/ + ); [parts.port] = takePattern(restAuthority, /^:(.*)/); if (!isValidPort(parts.port)) { return undefined; @@ -92,7 +95,11 @@ function parse(url: string, isBase = true): URLParts | undefined { parts.port = ""; } try { - parts.hostname = encodeHostname(parts.hostname).toLowerCase(); + const IPv6re = /^\[[0-9a-fA-F.:]{2,}\]$/; + if (!IPv6re.test(parts.hostname)) { + parts.hostname = encodeHostname(parts.hostname); // Non-IPv6 URLs + } + parts.hostname = parts.hostname.toLowerCase(); } catch { return undefined; } |