-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL: run IdnaTestV2.txt in WPT #38080
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4708e9a
URL: run IdnaTestV2.txt in WPT
annevk cad9be9
Modernize Python, add some filters
annevk 19157bb
No need to commit IdnaTestV2.txt
annevk 16fad0f
Rely on tools/ convention to allow print statements
annevk 0bcda0b
exclude STD3 and Bidi tests
annevk 21c552e
care less about where the script is invoked from
annevk bfa6666
ready for review
annevk 1a4e958
Update IdnaTestV2.window.js
annevk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 : ""}`); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be slightly nicer for other consumers like jsdom if this preprocessing, as well as the prepending of
https://
and appending of/x
, was done by the Python script that output the JSON file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not want to do that as I want
URLHost
(it'll happen one day!) to be able to consume the actual test.