Skip to content

Commit

Permalink
fix(cli/js/web): IPv6 hostname should be compressed (denoland#6772)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannLai committed Jul 16, 2020
1 parent de34166 commit d60f9c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cli/js/web/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,8 @@ function encodeHostname(s: string, isSpecial = true): string {
if (!s.match(/^\[[0-9A-Fa-f.:]{2,}\]$/)) {
throw new TypeError("Invalid hostname.");
}
return s.toLowerCase();
// IPv6 address compress
return s.toLowerCase().replace(/\b:?(?:0+:?){2,}/, "::");
}

let result = s;
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/unit/url_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ unitTest(function urlHostnameParsing(): void {
assertEquals(new URL("http:https://[::1]").hostname, "[::1]");
assertEquals(new URL("file:https://[::1]").hostname, "[::1]");
assertEquals(new URL("abcd:https://[::1]").hostname, "[::1]");
assertEquals(new URL("http:https://[0:f:0:0:f:f:0:0]").hostname, "[0:f::f:f:0:0]");
assertEquals(new URL("http:https://[0:0:5:6:7:8]").hostname, "[::5:6:7:8]");

// Forbidden host code point.
assertThrows(() => new URL("http:https:// a"), TypeError, "Invalid URL.");
Expand Down

0 comments on commit d60f9c2

Please sign in to comment.