From 465ad2a5ce7fe46c4f62c20206fb48d07085c645 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 20 Oct 2023 17:57:33 -0400 Subject: [PATCH] test: update `url` web platform tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/50264 Reviewed-By: Antoine du Hamel Reviewed-By: Michaƫl Zasso Reviewed-By: Moshe Atlow Reviewed-By: Luigi Pinca --- test/fixtures/wpt/README.md | 2 +- test/fixtures/wpt/url/failure.html | 2 + .../wpt/url/resources/a-element-origin.js | 4 ++ test/fixtures/wpt/url/resources/a-element.js | 4 ++ .../wpt/url/resources/setters_tests.json | 54 +++++++++++++++++++ .../wpt/url/resources/urltestdata.json | 1 - .../wpt/url/url-statics-canparse.any.js | 8 +-- .../wpt/url/urlsearchparams-delete.any.js | 11 ++++ .../wpt/url/urlsearchparams-has.any.js | 8 +++ test/fixtures/wpt/versions.json | 2 +- 10 files changed, 89 insertions(+), 7 deletions(-) diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 15f1fc695bd762..6404571a498200 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -27,7 +27,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/919874f84f/resources - streams: https://github.com/web-platform-tests/wpt/tree/517e945bbf/streams -- url: https://github.com/web-platform-tests/wpt/tree/84782d9315/url +- url: https://github.com/web-platform-tests/wpt/tree/c2d7e70b52/url - user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing - wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi - wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi diff --git a/test/fixtures/wpt/url/failure.html b/test/fixtures/wpt/url/failure.html index 8a408412668fd3..e61f462f97456f 100644 --- a/test/fixtures/wpt/url/failure.html +++ b/test/fixtures/wpt/url/failure.html @@ -10,6 +10,8 @@ function runTests(testData) { for (const test of testData) { + + // skip comments, inputs we expect to pass and relative URLs if (typeof test === "string" || !test.failure || test.base !== null) { continue; } diff --git a/test/fixtures/wpt/url/resources/a-element-origin.js b/test/fixtures/wpt/url/resources/a-element-origin.js index de72988ea93c12..c1c24c8986b4aa 100644 --- a/test/fixtures/wpt/url/resources/a-element-origin.js +++ b/test/fixtures/wpt/url/resources/a-element-origin.js @@ -21,6 +21,10 @@ function runURLTests(urlTests) { if (expected.base === null && expected.input.startsWith("#")) continue; + // HTML special cases data: and javascript: URLs in + if (expected.base !== null && (expected.base.startsWith("data:") || expected.base.startsWith("javascript:"))) + continue; + // We cannot use a null base for HTML tests const base = expected.base === null ? "about:blank" : expected.base; diff --git a/test/fixtures/wpt/url/resources/a-element.js b/test/fixtures/wpt/url/resources/a-element.js index d87937d002b24a..cff4160d328942 100644 --- a/test/fixtures/wpt/url/resources/a-element.js +++ b/test/fixtures/wpt/url/resources/a-element.js @@ -21,6 +21,10 @@ function runURLTests(urlTests) { if (expected.relativeTo === "any-base") continue; + // HTML special cases data: and javascript: URLs in + if (expected.base !== null && (expected.base.startsWith("data:") || expected.base.startsWith("javascript:"))) + continue; + // We cannot use a null base for HTML tests const base = expected.base === null ? "about:blank" : expected.base; diff --git a/test/fixtures/wpt/url/resources/setters_tests.json b/test/fixtures/wpt/url/resources/setters_tests.json index 347caf49ab0520..82adf4cdce270b 100644 --- a/test/fixtures/wpt/url/resources/setters_tests.json +++ b/test/fixtures/wpt/url/resources/setters_tests.json @@ -2021,6 +2021,24 @@ "href": "sc:/space%20", "pathname": "/space%20" } + }, + { + "comment": "Trailing space should be encoded", + "href": "http://example.net", + "new_value": " ", + "expected": { + "href": "http://example.net/%20", + "pathname": "/%20" + } + }, + { + "comment": "Trailing C0 control should be encoded", + "href": "http://example.net", + "new_value": "\u0000", + "expected": { + "href": "http://example.net/%00", + "pathname": "/%00" + } } ], "search": [ @@ -2141,6 +2159,24 @@ "href": "sc:space #fragment", "search": "" } + }, + { + "comment": "Trailing space should be encoded", + "href": "http://example.net", + "new_value": " ", + "expected": { + "href": "http://example.net/?%20", + "search": "?%20" + } + }, + { + "comment": "Trailing C0 control should be encoded", + "href": "http://example.net", + "new_value": "\u0000", + "expected": { + "href": "http://example.net/?%00", + "search": "?%00" + } } ], "hash": [ @@ -2311,6 +2347,24 @@ "href": "sc:space ?query", "hash": "" } + }, + { + "comment": "Trailing space should be encoded", + "href": "http://example.net", + "new_value": " ", + "expected": { + "href": "http://example.net/#%20", + "hash": "#%20" + } + }, + { + "comment": "Trailing C0 control should be encoded", + "href": "http://example.net", + "new_value": "\u0000", + "expected": { + "href": "http://example.net/#%00", + "hash": "#%00" + } } ], "href": [ diff --git a/test/fixtures/wpt/url/resources/urltestdata.json b/test/fixtures/wpt/url/resources/urltestdata.json index ec189871d90814..287a84b467a48b 100644 --- a/test/fixtures/wpt/url/resources/urltestdata.json +++ b/test/fixtures/wpt/url/resources/urltestdata.json @@ -7851,7 +7851,6 @@ "input": "blob:file://host/path", "base": null, "href": "blob:file://host/path", - "origin": "null", "protocol": "blob:", "username": "", "password": "", diff --git a/test/fixtures/wpt/url/url-statics-canparse.any.js b/test/fixtures/wpt/url/url-statics-canparse.any.js index c87fcb4f56fcdd..74f3da31f0d175 100644 --- a/test/fixtures/wpt/url/url-statics-canparse.any.js +++ b/test/fixtures/wpt/url/url-statics-canparse.any.js @@ -6,23 +6,23 @@ "expected": false }, { - "url": "a:b", + "url": "aaa:b", "base": undefined, "expected": true }, { "url": undefined, - "base": "a:b", + "base": "aaa:b", "expected": false }, { - "url": "a:/b", + "url": "aaa:/b", "base": undefined, "expected": true }, { "url": undefined, - "base": "a:/b", + "base": "aaa:/b", "expected": true }, { diff --git a/test/fixtures/wpt/url/urlsearchparams-delete.any.js b/test/fixtures/wpt/url/urlsearchparams-delete.any.js index f9c623b90b175d..c597142c51d5bf 100644 --- a/test/fixtures/wpt/url/urlsearchparams-delete.any.js +++ b/test/fixtures/wpt/url/urlsearchparams-delete.any.js @@ -70,3 +70,14 @@ test(() => { params.delete('a', 'c'); assert_equals(params.toString(), 'a=b&a=d'); }, "Two-argument delete()"); + +test(() => { + const params = new URLSearchParams(); + params.append('a', 'b'); + params.append('a', 'c'); + params.append('b', 'c'); + params.append('b', 'd'); + params.delete('b', 'c'); + params.delete('a', undefined); + assert_equals(params.toString(), 'b=d'); +}, "Two-argument delete() respects undefined as second arg"); diff --git a/test/fixtures/wpt/url/urlsearchparams-has.any.js b/test/fixtures/wpt/url/urlsearchparams-has.any.js index 54cbf286db4a3d..2133a5da2f8b91 100644 --- a/test/fixtures/wpt/url/urlsearchparams-has.any.js +++ b/test/fixtures/wpt/url/urlsearchparams-has.any.js @@ -35,3 +35,11 @@ test(() => { params.delete('a', 'b'); assert_true(params.has('a', 'd')); }, "Two-argument has()"); + +test(() => { + const params = new URLSearchParams("a=b&a=d&c&e&"); + assert_true(params.has('a', 'b')); + assert_false(params.has('a', 'c')); + assert_true(params.has('a', 'd')); + assert_true(params.has('a', undefined)); +}, "Two-argument has() respects undefined as second arg"); \ No newline at end of file diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index e069e93b99efd6..4b28c06e6c40df 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -68,7 +68,7 @@ "path": "streams" }, "url": { - "commit": "84782d931516aa13cfe32dc7eaa1377b4d947d66", + "commit": "c2d7e70b52cbd9a5b938aa32f37078d7a71e0b21", "path": "url" }, "user-timing": {