diff --git a/test/fixtures/wpt/url/failure.html b/test/fixtures/wpt/url/failure.html index d95b1d52d67..71efb0f27d9 100644 --- a/test/fixtures/wpt/url/failure.html +++ b/test/fixtures/wpt/url/failure.html @@ -29,8 +29,15 @@ function runTests(testData) { }, "URL's constructor's base argument: " + name) self.test(() => { - const url = new URL("about:blank") + const original = "http://user:pass@example.com:8080/path?query#fragment" + const url = new URL(original) assert_throws_js(TypeError, () => url.href = test.input) + const expected = new URL(original) + for (const property of ["href", "origin", "protocol", "username", "password", "host", "hostname", "port", "pathname", "search", "hash"]) { + assert_equals(url[property], expected[property], property) + } + url.hash = "changed" + assert_equals(url.href, "http://user:pass@example.com:8080/path?query#changed") }, "URL's href: " + name) // The following use cases resolve the URL input relative to the current diff --git a/test/fixtures/wpt/url/resources/setters_tests.json b/test/fixtures/wpt/url/resources/setters_tests.json index 221e77a951b..94d2dcd78d4 100644 --- a/test/fixtures/wpt/url/resources/setters_tests.json +++ b/test/fixtures/wpt/url/resources/setters_tests.json @@ -677,6 +677,16 @@ "port": "8080" } }, + { + "href": "http://example.net:8080", + "new_value": "example.com:0", + "expected": { + "href": "http://example.com:0/", + "host": "example.com:0", + "hostname": "example.com", + "port": "0" + } + }, { "comment": "Port number is unchanged if not specified", "href": "http://example.net:8080", @@ -697,6 +707,16 @@ "host": "example.net" } }, + { + "href": "http://example.net:8080/path", + "new_value": ":example.com:15", + "expected": { + "href": "http://example.net:8080/path", + "host": "example.net:8080", + "hostname": "example.net", + "port": "8080" + } + }, { "comment": "The empty host is OK for non-special schemes", "href": "view-source+http://example.net/foo", @@ -1066,6 +1086,16 @@ "port": "" } }, + { + "href": "file:///x", + "new_value": "example.net", + "expected": { + "href": "file://example.net/x", + "host": "example.net", + "hostname": "example.net", + "port": "" + } + }, { "href": "sc://test@test/", "new_value": "", @@ -1519,6 +1549,16 @@ "port": "" } }, + { + "href": "file:///x", + "new_value": "example.net", + "expected": { + "href": "file://example.net/x", + "host": "example.net", + "hostname": "example.net", + "port": "" + } + }, { "href": "sc://test@test/", "new_value": "", @@ -1693,6 +1733,16 @@ "port": "" } }, + { + "href": "http://example.net:8080", + "new_value": "0", + "expected": { + "href": "http://example.net:0/", + "host": "example.net:0", + "hostname": "example.net", + "port": "0" + } + }, { "comment": "Default port number is removed", "href": "http://example.net:8080", @@ -2034,6 +2084,14 @@ "pathname": "/home" } }, + { + "href": "https://example.net/home#nav", + "new_value": "", + "expected": { + "href": "https://example.net/#nav", + "pathname": "/" + } + }, { "comment": "\\ is a segment delimiter for 'special' URLs", "href": "http://example.net/home?lang=fr#nav", diff --git a/test/fixtures/wpt/url/resources/urltestdata-javascript-only.json b/test/fixtures/wpt/url/resources/urltestdata-javascript-only.json index a3793c1f472..01b37526b99 100644 --- a/test/fixtures/wpt/url/resources/urltestdata-javascript-only.json +++ b/test/fixtures/wpt/url/resources/urltestdata-javascript-only.json @@ -14,5 +14,20 @@ "pathname": "/%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF", "search": "?%EF%BF%BD%F0%90%9F%BE%EF%BF%BD%EF%B7%90%EF%B7%8F%EF%B7%AF%EF%B7%B0%EF%BF%BE%EF%BF%BF", "hash": "" + }, + { + "input": "b/c", + "base": "http://example.com/\uD801/b", + "href": "http://example.com/%EF%BF%BD/b/c", + "origin": "http://example.com", + "protocol": "http:", + "username": "", + "password": "", + "host": "example.com", + "hostname": "example.com", + "port": "", + "pathname": "/%EF%BF%BD/b/c", + "search": "", + "hash": "" } ] diff --git a/test/fixtures/wpt/url/resources/urltestdata.json b/test/fixtures/wpt/url/resources/urltestdata.json index c98300ec781..950569a8024 100644 --- a/test/fixtures/wpt/url/resources/urltestdata.json +++ b/test/fixtures/wpt/url/resources/urltestdata.json @@ -10721,5 +10721,81 @@ "pathname": "blank", "search": "", "hash": "#%00%01%1F%20!%22#$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_%60az{|}~%7F%C2%80%C2%81%C3%89%C3%A9" + }, + "# Relative resolution against empty-path and path-only non-special base URLs with query/fragment", + { + "input": "p", + "base": "git://host?q#r", + "href": "git://host/p", + "origin": "null", + "protocol": "git:", + "username": "", + "password": "", + "host": "host", + "hostname": "host", + "port": "", + "pathname": "/p", + "search": "", + "hash": "" + }, + { + "input": "?q2", + "base": "git://host?q#r", + "href": "git://host?q2", + "origin": "null", + "protocol": "git:", + "username": "", + "password": "", + "host": "host", + "hostname": "host", + "port": "", + "pathname": "", + "search": "?q2", + "hash": "" + }, + { + "input": "#h", + "base": "git://host?q#r", + "href": "git://host?q#h", + "origin": "null", + "protocol": "git:", + "username": "", + "password": "", + "host": "host", + "hostname": "host", + "port": "", + "pathname": "", + "search": "?q", + "hash": "#h" + }, + { + "input": "?q2", + "base": "git:/.//a?q#r", + "href": "git:/.//a?q2", + "origin": "null", + "protocol": "git:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "//a", + "search": "?q2", + "hash": "" + }, + { + "input": "#h", + "base": "git:/.//a?q#r", + "href": "git:/.//a?q#h", + "origin": "null", + "protocol": "git:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "//a", + "search": "?q", + "hash": "#h" } ] diff --git a/test/fixtures/wpt/url/url-setters-lone-surrogates.any.js b/test/fixtures/wpt/url/url-setters-lone-surrogates.any.js new file mode 100644 index 00000000000..1a81723d946 --- /dev/null +++ b/test/fixtures/wpt/url/url-setters-lone-surrogates.any.js @@ -0,0 +1,44 @@ +// Not in setters_tests.json since lone surrogates are not portable JSON. + +[{ + property: 'pathname', + newValue: '\uDC01\uD802a', + expected: { + href: 'http://example.net/%EF%BF%BD%EF%BF%BDa', + pathname: '/%EF%BF%BD%EF%BF%BDa' + } +}, + { + property: 'search', + newValue: '\uDC01\uD802a', + expected: { + href: 'http://example.net/?%EF%BF%BD%EF%BF%BDa', + search: '?%EF%BF%BD%EF%BF%BDa' + } + }, + { + property: 'hash', + newValue: '\uDC01\uD802a', + expected: { + href: 'http://example.net/#%EF%BF%BD%EF%BF%BDa', + hash: '#%EF%BF%BD%EF%BF%BDa' + } + }, + { + property: 'host', + newValue: 'exa\uDC01\uD802mple.com', + expected: {href: 'http://example.net/', host: 'example.net'} + }, + { + property: 'hostname', + newValue: 'exa\uDC01\uD802mple.com', + expected: {href: 'http://example.net/', hostname: 'example.net'} + }].forEach(({property, newValue, expected}) => { + test(() => { + const url = new URL('http://example.net/'); + url[property] = newValue; + for (const [key, value] of Object.entries(expected)) { + assert_equals(url[key], value, key); + } + }, `Setting ${property} to a value with lone surrogates`); +}); diff --git a/test/fixtures/wpt/url/urlsearchparams-constructor.any.js b/test/fixtures/wpt/url/urlsearchparams-constructor.any.js index d482911350b..ecd341a431e 100644 --- a/test/fixtures/wpt/url/urlsearchparams-constructor.any.js +++ b/test/fixtures/wpt/url/urlsearchparams-constructor.any.js @@ -19,6 +19,15 @@ test(function () { assert_equals(params.toString(), "a=b") }, 'URLSearchParams constructor, remove leading "?"') +test(function() { + var params = new URLSearchParams('??a=b') + assert_equals(params.toString(), '%3Fa=b') + params = new URLSearchParams('?') + assert_equals(params.toString(), '') + params = new URLSearchParams('??') + assert_equals(params.toString(), '%3F=') +}, 'URLSearchParams constructor, remove only one leading "?"') + test(() => { var params = new URLSearchParams(DOMException); assert_equals(params.toString(), "INDEX_SIZE_ERR=1&DOMSTRING_SIZE_ERR=2&HIERARCHY_REQUEST_ERR=3&WRONG_DOCUMENT_ERR=4&INVALID_CHARACTER_ERR=5&NO_DATA_ALLOWED_ERR=6&NO_MODIFICATION_ALLOWED_ERR=7&NOT_FOUND_ERR=8&NOT_SUPPORTED_ERR=9&INUSE_ATTRIBUTE_ERR=10&INVALID_STATE_ERR=11&SYNTAX_ERR=12&INVALID_MODIFICATION_ERR=13&NAMESPACE_ERR=14&INVALID_ACCESS_ERR=15&VALIDATION_ERR=16&TYPE_MISMATCH_ERR=17&SECURITY_ERR=18&NETWORK_ERR=19&ABORT_ERR=20&URL_MISMATCH_ERR=21"A_EXCEEDED_ERR=22&TIMEOUT_ERR=23&INVALID_NODE_TYPE_ERR=24&DATA_CLONE_ERR=25") @@ -130,6 +139,20 @@ test(function() { assert_equals(newParams.get('query'), testValue); }, 'Parse encoded +'); +test(function() { + var params = new URLSearchParams('a=b%2Bc'); + assert_equals(params.get('a'), 'b+c'); + params = new URLSearchParams('a%2Bb=c'); + assert_equals(params.get('a+b'), 'c'); +}, 'Parse %2B'); + +test(function() { + var params = new URLSearchParams('='); + assert_true(params.has('')); + assert_equals(params.get(''), ''); + assert_equals(params.toString(), '='); +}, 'Parse ='); + test(function() { var params = new URLSearchParams('a=b c'); assert_equals(params.get('a'), 'b c'); @@ -196,6 +219,18 @@ test(function() { assert_throws_js(TypeError, function() { new URLSearchParams([[1,2,3]]); }); }, "Constructor with sequence of sequences of strings"); +test(function() { + var params = new URLSearchParams([[1, 2], ['a', 'b']]); + assert_equals(params.toString(), '1=2&a=b'); +}, 'Constructor with sequence of sequences of non-strings'); + +test(function() { + var params = new URLSearchParams({1: 2, 'a': 'b'}); + assert_equals(params.toString(), '1=2&a=b'); + params = new URLSearchParams({false: true, 0: 'foo'}); + assert_equals(params.toString(), '0=foo&false=true'); +}, 'Constructor with record of non-strings, in property order'); + [ { "input": {"+": "%C2"}, "output": [["+", "%C2"]], "name": "object with +" }, { "input": {c: "x", a: "?"}, "output": [["c", "x"], ["a", "?"]], "name": "object with two keys" }, diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index ac61a9f3712..72a345fe0ad 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -76,7 +76,7 @@ "path": "streams" }, "url": { - "commit": "8c17bfeb3e66a2986be16b0e004f85ace68db647", + "commit": "dca32277cbf3d40b3ec20bba999a987b0ea51ed7", "path": "url" }, "urlpattern": {