test: update web-platform tests for url

PR-URL: https://github.com/nodejs/node/pull/46547
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>
This commit is contained in:
Yagiz Nizipli authored and Node.js GitHub Bot committed 2023-02-18 22:43:24 +00:00
1 parent 261bf9652b
commit 0850ddafca
17 files changed
+10305 -8

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ Last update:
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
- resources: https://github.com/web-platform-tests/wpt/tree/fbf1e7d247/resources
- streams: https://github.com/web-platform-tests/wpt/tree/9e5ef42bd3/streams
- url: https://github.com/web-platform-tests/wpt/tree/0a187bc169/url
- url: https://github.com/web-platform-tests/wpt/tree/f1ade799d0/url
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
+41
View File
@@ -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 : ""}`);
}
}
+5
View File
@@ -3,8 +3,13 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>URL Test</title>
<meta name="variant" content="?include=file"/>
<meta name="variant" content="?include=javascript"/>
<meta name="variant" content="?include=mailto"/>
<meta name="variant" content="?exclude=(file|javascript|mailto)"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/subset-tests-by-key.js"></script>
<base id="base"/>
</head>
<body>
+5
View File
@@ -1,7 +1,12 @@
<!doctype html>
<meta charset=utf-8>
<meta name="variant" content="?include=file">
<meta name="variant" content="?include=javascript">
<meta name="variant" content="?include=mailto">
<meta name="variant" content="?exclude=(file|javascript|mailto)">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/subset-tests-by-key.js"></script>
<base id=base>
<div id=log></div>
<script src=resources/a-element.js></script>
+8
View File
@@ -28,4 +28,12 @@ test(function() {
assert_equals(URL.domainToUnicode, undefined);
}, "URL.domainToUnicode should be undefined");
test(() => {
assert_throws_dom("DataCloneError", () => self.structuredClone(new URL("about:blank")));
}, "URL: no structured serialize/deserialize support");
test(() => {
assert_throws_dom("DataCloneError", () => self.structuredClone(new URLSearchParams()));
}, "URLSearchParams: no structured serialize/deserialize support");
done();
File diff suppressed because it is too large. Load diff
+11 -1
View File
@@ -19,7 +19,17 @@ function runURLTests(urltests) {
// skip without base because you cannot unset the baseURL of a document
if (expected.base === null) continue;
test(function() {
function getKey(expected) {
if (expected.protocol) {
return expected.protocol.replace(":", "");
}
if (expected.failure) {
return expected.input.split(":")[0];
}
return "other";
}
subsetTestByKey(getKey(expected), test, function() {
var url = bURL(expected.input, expected.base)
if(expected.failure) {
if(url.protocol !== ':') {
+157 -1
View File
@@ -269,6 +269,57 @@
"protocol": "https:",
"port": ""
}
},
{
"comment": "Tab and newline are stripped",
"href": "http://test/",
"new_value": "h\u000D\u000Att\u0009ps",
"expected": {
"href": "https://test/",
"protocol": "https:",
"port": ""
}
},
{
"href": "http://test/",
"new_value": "https\u000D",
"expected": {
"href": "https://test/",
"protocol": "https:"
}
},
{
"comment": "Non-tab/newline C0 controls result in no-op",
"href": "http://test/",
"new_value": "https\u0000",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
},
{
"href": "http://test/",
"new_value": "https\u000C",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
},
{
"href": "http://test/",
"new_value": "https\u000E",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
},
{
"href": "http://test/",
"new_value": "https\u0020",
"expected": {
"href": "http://test/",
"protocol": "http:"
}
}
],
"username": [
@@ -1603,7 +1654,7 @@
],
"pathname": [
{
"comment": "Cannot-be-a-base don’t have a path",
"comment": "Opaque paths cannot be set",
"href": "mailto:me@example.net",
"new_value": "/foo",
"expected": {
@@ -1611,6 +1662,22 @@
"pathname": "me@example.net"
}
},
{
"href": "data:original",
"new_value": "new value",
"expected": {
"href": "data:original",
"pathname": "original"
}
},
{
"href": "sc:original",
"new_value": "new value",
"expected": {
"href": "sc:original",
"pathname": "original"
}
},
{
"comment": "Special URLs cannot have their paths erased",
"href": "file:///some/path",
@@ -1830,6 +1897,23 @@
"href": "non-spec:/p",
"pathname": "/p"
}
},
{
"comment": "Non-special URLs with non-opaque paths percent-encode U+0020",
"href": "data:/nospace",
"new_value": "space ",
"expected": {
"href": "data:/space%20",
"pathname": "/space%20"
}
},
{
"href": "sc:/nospace",
"new_value": "space ",
"expected": {
"href": "sc:/space%20",
"pathname": "/space%20"
}
}
],
"search": [
@@ -1914,6 +1998,42 @@
"href": "http://example.net/?%c3%89t%C3%A9",
"search": "?%c3%89t%C3%A9"
}
},
{
"comment": "Drop trailing spaces from trailing opaque paths",
"href": "data:space ?query",
"new_value": "",
"expected": {
"href": "data:space",
"pathname": "space",
"search": ""
}
},
{
"href": "sc:space ?query",
"new_value": "",
"expected": {
"href": "sc:space",
"pathname": "space",
"search": ""
}
},
{
"comment": "Do not drop trailing spaces from non-trailing opaque paths",
"href": "data:space ?query#fragment",
"new_value": "",
"expected": {
"href": "data:space #fragment",
"search": ""
}
},
{
"href": "sc:space ?query#fragment",
"new_value": "",
"expected": {
"href": "sc:space #fragment",
"search": ""
}
}
],
"hash": [
@@ -2048,6 +2168,42 @@
"href": "javascript:alert(1)#castle",
"hash": "#castle"
}
},
{
"comment": "Drop trailing spaces from trailing opaque paths",
"href": "data:space #fragment",
"new_value": "",
"expected": {
"href": "data:space",
"pathname": "space",
"hash": ""
}
},
{
"href": "sc:space #fragment",
"new_value": "",
"expected": {
"href": "sc:space",
"pathname": "space",
"hash": ""
}
},
{
"comment": "Do not drop trailing spaces from non-trailing opaque paths",
"href": "data:space ?query#fragment",
"new_value": "",
"expected": {
"href": "data:space ?query",
"hash": ""
}
},
{
"href": "sc:space ?query#fragment",
"new_value": "",
"expected": {
"href": "sc:space ?query",
"hash": ""
}
}
]
}
+17
View File
@@ -61,6 +61,10 @@
"input": "xn--a.ß",
"output": null
},
{
"input": "xn--ls8h=",
"output": null
},
{
"comment": "Invalid Punycode (contains non-ASCII character)",
"input": "xn--tešla",
@@ -172,5 +176,18 @@
{
"input": "xn--",
"output": null
},
{
"comment": "Interesting UseSTD3ASCIIRules=false cases",
"input": "≠",
"output": "xn--1ch"
},
{
"input": "≮",
"output": "xn--gdh"
},
{
"input": "≯",
"output": "xn--hdh"
}
]
+248
View File
@@ -3917,6 +3917,22 @@
"search": "",
"hash": ""
},
"Non-special domains with empty labels",
{
"input": "h://.",
"base": "about:blank",
"href": "h://.",
"origin": "null",
"protocol": "h:",
"username": "",
"password": "",
"host": ".",
"hostname": ".",
"port": "",
"pathname": "",
"search": "",
"hash": ""
},
"Broken IPv6",
{
"input": "http://[www.google.com]/",
@@ -3948,6 +3964,16 @@
"base": "http://other.com/",
"failure": true
},
{
"input": "http://[::%31]",
"base": "http://other.com/",
"failure": true
},
{
"input": "http://%5B::1]",
"base": "http://other.com/",
"failure": true
},
"Misc Unicode",
{
"input": "http://foo:💩@example.com/bar",
@@ -8124,6 +8150,21 @@
"search": "",
"hash": ""
},
"IDNA hostnames which get mapped to 'localhost'",
{
"input": "file://loC𝐀𝐋𝐇𝐨𝐬𝐭/usr/bin",
"base": "about:blank",
"href": "file:///usr/bin",
"protocol": "file:",
"username": "",
"password": "",
"host": "",
"hostname": "",
"port": "",
"pathname": "/usr/bin",
"search": "",
"hash": ""
},
"Empty host after the domain to ASCII",
{
"input": "file://\u00ad/p",
@@ -8609,5 +8650,212 @@
"input": "http://💩.123/",
"base": "about:blank",
"failure": true
},
"U+0000 and U+FFFF in various places",
{
"input": "https://\u0000y",
"base": "about:blank",
"failure": true
},
{
"input": "https://x/\u0000y",
"base": "about:blank",
"hash": "",
"host": "x",
"hostname": "x",
"href": "https://x/%00y",
"password": "",
"pathname": "/%00y",
"port": "",
"protocol": "https:",
"search": "",
"username": ""
},
{
"input": "https://x/?\u0000y",
"base": "about:blank",
"hash": "",
"host": "x",
"hostname": "x",
"href": "https://x/?%00y",
"password": "",
"pathname": "/",
"port": "",
"protocol": "https:",
"search": "?%00y",
"username": ""
},
{
"input": "https://x/?#\u0000y",
"base": "about:blank",
"hash": "#%00y",
"host": "x",
"hostname": "x",
"href": "https://x/?#%00y",
"password": "",
"pathname": "/",
"port": "",
"protocol": "https:",
"search": "",
"username": ""
},
{
"input": "https://\uFFFFy",
"base": "about:blank",
"failure": true
},
{
"input": "https://x/\uFFFFy",
"base": "about:blank",
"hash": "",
"host": "x",
"hostname": "x",
"href": "https://x/%EF%BF%BFy",
"password": "",
"pathname": "/%EF%BF%BFy",
"port": "",
"protocol": "https:",
"search": "",
"username": ""
},
{
"input": "https://x/?\uFFFFy",
"base": "about:blank",
"hash": "",
"host": "x",
"hostname": "x",
"href": "https://x/?%EF%BF%BFy",
"password": "",
"pathname": "/",
"port": "",
"protocol": "https:",
"search": "?%EF%BF%BFy",
"username": ""
},
{
"input": "https://x/?#\uFFFFy",
"base": "about:blank",
"hash": "#%EF%BF%BFy",
"host": "x",
"hostname": "x",
"href": "https://x/?#%EF%BF%BFy",
"password": "",
"pathname": "/",
"port": "",
"protocol": "https:",
"search": "",
"username": ""
},
{
"input": "non-special:\u0000y",
"base": "about:blank",
"hash": "",
"host": "",
"hostname": "",
"href": "non-special:%00y",
"password": "",
"pathname": "%00y",
"port": "",
"protocol": "non-special:",
"search": "",
"username": ""
},
{
"input": "non-special:x/\u0000y",
"base": "about:blank",
"hash": "",
"host": "",
"hostname": "",
"href": "non-special:x/%00y",
"password": "",
"pathname": "x/%00y",
"port": "",
"protocol": "non-special:",
"search": "",
"username": ""
},
{
"input": "non-special:x/?\u0000y",
"base": "about:blank",
"hash": "",
"host": "",
"hostname": "",
"href": "non-special:x/?%00y",
"password": "",
"pathname": "x/",
"port": "",
"protocol": "non-special:",
"search": "?%00y",
"username": ""
},
{
"input": "non-special:x/?#\u0000y",
"base": "about:blank",
"hash": "#%00y",
"host": "",
"hostname": "",
"href": "non-special:x/?#%00y",
"password": "",
"pathname": "x/",
"port": "",
"protocol": "non-special:",
"search": "",
"username": ""
},
{
"input": "non-special:\uFFFFy",
"base": "about:blank",
"hash": "",
"host": "",
"hostname": "",
"href": "non-special:%EF%BF%BFy",
"password": "",
"pathname": "%EF%BF%BFy",
"port": "",
"protocol": "non-special:",
"search": "",
"username": ""
},
{
"input": "non-special:x/\uFFFFy",
"base": "about:blank",
"hash": "",
"host": "",
"hostname": "",
"href": "non-special:x/%EF%BF%BFy",
"password": "",
"pathname": "x/%EF%BF%BFy",
"port": "",
"protocol": "non-special:",
"search": "",
"username": ""
},
{
"input": "non-special:x/?\uFFFFy",
"base": "about:blank",
"hash": "",
"host": "",
"hostname": "",
"href": "non-special:x/?%EF%BF%BFy",
"password": "",
"pathname": "x/",
"port": "",
"protocol": "non-special:",
"search": "?%EF%BF%BFy",
"username": ""
},
{
"input": "non-special:x/?#\uFFFFy",
"base": "about:blank",
"hash": "#%EF%BF%BFy",
"host": "",
"hostname": "",
"href": "non-special:x/?#%EF%BF%BFy",
"password": "",
"pathname": "x/",
"port": "",
"protocol": "non-special:",
"search": "",
"username": ""
}
]
+16 -1
View File
@@ -1,4 +1,9 @@
// META: script=/common/subset-tests-by-key.js
// META: timeout=long
// META: variant=?include=file
// META: variant=?include=javascript
// META: variant=?include=mailto
// META: variant=?exclude=(file|javascript|mailto)
function bURL(url, base) {
return base ? new URL(url, base) : new URL(url)
@@ -9,7 +14,17 @@ function runURLTests(urltests) {
var expected = urltests[i]
if (typeof expected === "string") continue // skip comments
test(function() {
function getKey(expected) {
if (expected.protocol) {
return expected.protocol.replace(":", "");
}
if (expected.failure) {
return expected.input.split(":")[0];
}
return "other";
}
subsetTestByKey(getKey(expected), test, function() {
if (expected.failure) {
assert_throws_js(TypeError, function() {
bURL(expected.input, expected.base)
+9 -2
View File
@@ -1,3 +1,9 @@
// META: script=/common/subset-tests-by-key.js
// META: variant=?include=file
// META: variant=?include=javascript
// META: variant=?include=mailto
// META: variant=?exclude=(file|javascript|mailto)
// Keep this file in sync with url-setters.any.js.
promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
@@ -15,7 +21,8 @@ function runURLSettersTests(all_test_cases) {
if ("comment" in test_case) {
name += " " + test_case.comment;
}
test(function() {
const key = test_case.href.split(":")[0];
subsetTestByKey(key, test, function() {
var url = document.createElement("a");
url.href = test_case.href;
url[attribute_to_be_set] = test_case.new_value;
@@ -23,7 +30,7 @@ function runURLSettersTests(all_test_cases) {
assert_equals(url[attribute], test_case.expected[attribute])
}
}, "<a>: " + name)
test(function() {
subsetTestByKey(key, test, function() {
var url = document.createElement("area");
url.href = test_case.href;
url[attribute_to_be_set] = test_case.new_value;
+8 -1
View File
@@ -1,3 +1,9 @@
// META: script=/common/subset-tests-by-key.js
// META: variant=?include=file
// META: variant=?include=javascript
// META: variant=?include=mailto
// META: variant=?exclude=(file|javascript|mailto)
// Keep this file in sync with url-setters-a-area.window.js.
promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
@@ -15,7 +21,8 @@ function runURLSettersTests(all_test_cases) {
if ("comment" in test_case) {
name += " " + test_case.comment;
}
test(function() {
const key = test_case.href.split(":")[0];
subsetTestByKey(key, test, function() {
var url = new URL(test_case.href);
url[attribute_to_be_set] = test_case.new_value;
for (var attribute in test_case.expected) {
+18
View File
@@ -43,3 +43,21 @@ test(function() {
assert_equals(url.href, 'http://example.com/', 'url.href does not have ?');
assert_equals(url.search, '', 'url.search does not have ?');
}, 'Removing non-existent param removes ? from URL');
test(() => {
const url = new URL('data:space ?test');
assert_true(url.searchParams.has('test'));
url.searchParams.delete('test');
assert_false(url.searchParams.has('test'));
assert_equals(url.search, '');
assert_equals(url.pathname, 'space');
assert_equals(url.href, 'data:space');
}, 'Changing the query of a URL with an opaque path can impact the path');
test(() => {
const url = new URL('data:space ?test#test');
url.searchParams.delete('test');
assert_equals(url.search, '');
assert_equals(url.pathname, 'space ');
assert_equals(url.href, 'data:space #test');
}, 'Changing the query of a URL with an opaque path can impact the path if the URL has no fragment');
+1 -1
View File
@@ -72,7 +72,7 @@
"path": "streams"
},
"url": {
"commit": "0a187bc16933e67dfb8755935143a6dd5a9e12f2",
"commit": "f1ade799d04b72b0ff75c13e988744c2cd873741",
"path": "url"
},
"user-timing": {
+3
View File
@@ -23,5 +23,8 @@
},
"url-setters-a-area.window.js": {
"skip": "already tested in url-setters.any.js"
},
"IdnaTestV2.window.js": {
"requires": ["small-icu"]
}
}
+3
View File
@@ -14,4 +14,7 @@ runner.setScriptModifier((obj) => {
}
});
runner.pretendGlobalThisAs('Window');
runner.setInitScript(`
globalThis.location = {};
`);
runner.runJsTests();