-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update web-platform tests for url
PR-URL: #46547 Backport-PR-URL: #47435 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
1 parent
484c4f6
commit 972bdee
Showing
17 changed files
with
10,305 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
promise_test(() => fetch("resources/IdnaTestV2.json").then(res => res.json()).then(runTests), "Loading data…"); | ||
|
||
// Performance impact of this seems negligible (performance.now() diff in WebKit went from 48 to 52) | ||
// and there was a preference to let more non-ASCII hit the parser. | ||
function encodeHostEndingCodePoints(input) { | ||
let output = ""; | ||
for (const codePoint of input) { | ||
if ([":", "/", "?", "#", "\\"].includes(codePoint)) { | ||
output += encodeURIComponent(codePoint); | ||
} else { | ||
output += codePoint; | ||
} | ||
} | ||
return output; | ||
} | ||
|
||
function runTests(idnaTests) { | ||
for (const idnaTest of idnaTests) { | ||
if (typeof idnaTest === "string") { | ||
continue // skip comments | ||
} | ||
if (idnaTest.input === "") { | ||
continue // cannot test empty string input through new URL() | ||
} | ||
// Percent-encode the input such that ? and equivalent code points do not end up counting as | ||
// part of the URL, but are parsed through the host parser instead. | ||
const encodedInput = encodeHostEndingCodePoints(idnaTest.input); | ||
|
||
test(() => { | ||
if (idnaTest.output === null) { | ||
assert_throws_js(TypeError, () => new URL(`https://${encodedInput}/x`)); | ||
} else { | ||
const url = new URL(`https://${encodedInput}/x`); | ||
assert_equals(url.host, idnaTest.output); | ||
assert_equals(url.hostname, idnaTest.output); | ||
assert_equals(url.pathname, "/x"); | ||
assert_equals(url.href, `https://${idnaTest.output}/x`); | ||
} | ||
}, `ToASCII("${idnaTest.input}")${idnaTest.comment ? " " + idnaTest.comment : ""}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.