mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(cli/js/web): IPv6 hostname should be compressed (#6772)
This commit is contained in:
parent
de34166891
commit
d60f9c2549
2 changed files with 4 additions and 1 deletions
|
@ -565,7 +565,8 @@ function encodeHostname(s: string, isSpecial = true): string {
|
||||||
if (!s.match(/^\[[0-9A-Fa-f.:]{2,}\]$/)) {
|
if (!s.match(/^\[[0-9A-Fa-f.:]{2,}\]$/)) {
|
||||||
throw new TypeError("Invalid hostname.");
|
throw new TypeError("Invalid hostname.");
|
||||||
}
|
}
|
||||||
return s.toLowerCase();
|
// IPv6 address compress
|
||||||
|
return s.toLowerCase().replace(/\b:?(?:0+:?){2,}/, "::");
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = s;
|
let result = s;
|
||||||
|
|
|
@ -44,6 +44,8 @@ unitTest(function urlHostnameParsing(): void {
|
||||||
assertEquals(new URL("http://[::1]").hostname, "[::1]");
|
assertEquals(new URL("http://[::1]").hostname, "[::1]");
|
||||||
assertEquals(new URL("file://[::1]").hostname, "[::1]");
|
assertEquals(new URL("file://[::1]").hostname, "[::1]");
|
||||||
assertEquals(new URL("abcd://[::1]").hostname, "[::1]");
|
assertEquals(new URL("abcd://[::1]").hostname, "[::1]");
|
||||||
|
assertEquals(new URL("http://[0:f:0:0:f:f:0:0]").hostname, "[0:f::f:f:0:0]");
|
||||||
|
assertEquals(new URL("http://[0:0:5:6:7:8]").hostname, "[::5:6:7:8]");
|
||||||
|
|
||||||
// Forbidden host code point.
|
// Forbidden host code point.
|
||||||
assertThrows(() => new URL("http:// a"), TypeError, "Invalid URL.");
|
assertThrows(() => new URL("http:// a"), TypeError, "Invalid URL.");
|
||||||
|
|
Loading…
Reference in a new issue