Skip to content

URL and HTML: correct protocol setter tests #38032

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

Merged
merged 5 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[
'x',
'data',
// 'mailto' opens an email client in Firefox...
// 'mailto' opens an email client in Chrome and Firefox and then ends up passing anyway...
'file',
'ftp',
'http+x'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<title>Set location.protocol to the scheme it already was</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<iframe src=/common/blank.html></iframe>
<iframe src=/common/blank.html></iframe>
<iframe src=/common/blank.html></iframe>
<iframe src=/common/blank.html></iframe>
<script>
self.onload = () => {
[
"http",
"ht\x0Atp",
"http\x0A",
"\x09ht\x09\x0AtP"
].forEach((val, index) => {
async_test(t => {
self[index].frameElement.onload = t.step_func_done(() => {
assert_equals(self[index].location.protocol, "http:");
});
self[index].location.protocol = val;
}, `Set location.protocol to ${encodeURI(val)} (percent-encoded)`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're actually setting it to the outputted value percent-decoded, right?

Note that you might be able to get away with no encoding in the assert message at all; I kind of remember the WPT harness doing some escaping for us.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. It doesn't seem to do any escaping if I remove encodeURI(). It does seem like I could also invoke escape() but that appears to do the same thing for these inputs.

I'll update the message to "(percent-encoded here for clarity)".

});
}
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<title>Set location.protocol to broken schemes</title>
<title>Set location.protocol to schemes that throw</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
Expand Down Expand Up @@ -32,14 +32,11 @@
}
</script>"></iframe>
<script>
// Tests with '\x0A' (i.e., '\n') don't conform to the URL Standard as of the
// time of writing, as according to spec they should be ignored.
// See https://github.com/whatwg/url/issues/609.

let broken = [
const broken = [
'\x00',
'\x01',
'\x0A',
'\x09', // becomes the empty string
'\x0A', // becomes the empty string
'\x20',
'\x21',
'\x7F',
Expand All @@ -49,7 +46,6 @@
'†',
'\x00x',
'\x01x',
'\x0Ax',
'\x20x',
'\x21x',
'\x7Fx',
Expand All @@ -59,7 +55,6 @@
'†x',
'\x00X',
'\x01X',
'\x0AX',
'\x20X',
'\x21X',
'\x7FX',
Expand All @@ -69,7 +64,6 @@
'†X',
'x\x00',
'x\x01',
'x\x0A',
'x\x20',
'x\x21',
'x\x7F',
Expand All @@ -78,17 +72,15 @@
'x†',
'X\x00',
'X\x01',
'X\x0A',
'X\x20',
'X\x21',
'X\x7F',
'X\x80',
'X\xFF',
'X†',
'a\x0A',
'a+-.\x0A'
]
;broken.forEach((val) => {
];

broken.forEach(val => {
test(() => {
assert_throws_dom("SyntaxError", () => { location.protocol = val })
}, encodeURI(val) + " (percent-encoded) is not a scheme")
Expand Down
10 changes: 10 additions & 0 deletions url/resources/setters_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@
"protocol": "https:",
"port": ""
}
},
{
"comment": "Tab and newline are stripped",
"href": "http://test/",
"new_value": "h\u000A\u000Att\u0009ps",
"expected": {
"href": "https://test/",
"protocol": "https:",
"port": ""
}
}
],
"username": [
Expand Down