From 8aa9f61e24faa02672970225ce348a1f6768bf8c Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 6 May 2020 12:04:31 +0000 Subject: [PATCH] Bug 1633415 [wpt PR 23265] - URL: stripping of tab and newlines in setters, a=testonly Automatic update from web-platform-tests URL: stripping of tab and newlines in setters Closes https://github.com/whatwg/url/issues/419. -- wpt-commits: 04aec1fa1b1f5cf8833b61682da707b7fd47bef6 wpt-pr: 23265 UltraBlame original commit: 4f721ebd4db736cb0f87059675e217194088b753 --- .../tests/url/url-setters-stripping.any.js | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 testing/web-platform/tests/url/url-setters-stripping.any.js diff --git a/testing/web-platform/tests/url/url-setters-stripping.any.js b/testing/web-platform/tests/url/url-setters-stripping.any.js new file mode 100644 index 0000000000000..71804dcb034af --- /dev/null +++ b/testing/web-platform/tests/url/url-setters-stripping.any.js @@ -0,0 +1,125 @@ +function urlString({ scheme = "https", + username = "username", + password = "password", + host = "host", + port = "8000", + pathname = "path", + search = "query", + hash = "fragment" }) { + return `${scheme}://${username}:${password}@${host}:${port}/${pathname}?${search}#${hash}`; +} + +function urlRecord(scheme) { + return new URL(urlString({ scheme })); +} + +for(const scheme of ["https", "wpt++"]) { + for(let i = 0; i < 0x20; i++) { + const stripped = i === 0x09 || i === 0x0A || i === 0x0D; + + + + if (i !== 0 && i !== 0x1F && !stripped) { + continue; + } + + const cpString = String.fromCodePoint(i); + const cpReference = "U+" + i.toString(16).toUpperCase().padStart(4, "0"); + + test(() => { + const expected = scheme === "https" ? (stripped ? "http" : "https") : (stripped ? "wpt--" : "wpt++"); + const url = urlRecord(scheme); + url.protocol = String.fromCodePoint(i) + (scheme === "https" ? "http" : "wpt--"); + assert_equals(url.protocol, expected + ":", "property"); + assert_equals(url.href, urlString({ scheme: expected }), "href"); + }, `Setting protocol with leading ${cpReference} (${scheme}:)`); + + test(() => { + const expected = scheme === "https" ? (stripped ? "http" : "https") : (stripped ? "wpt--" : "wpt++"); + const url = urlRecord(scheme); + url.protocol = (scheme === "https" ? "http" : "wpt--") + String.fromCodePoint(i); + assert_equals(url.protocol, expected + ":", "property"); + assert_equals(url.href, urlString({ scheme: expected }), "href"); + }, `Setting protocol with ${cpReference} before inserted colon (${scheme}:)`); + + + + + for (const property of ["username", "password"]) { + for (const [type, expected, input] of [ + ["leading", encodeURIComponent(cpString) + "test", String.fromCodePoint(i) + "test"], + ["middle", "te" + encodeURIComponent(cpString) + "st", "te" + String.fromCodePoint(i) + "st"], + ["trailing", "test" + encodeURIComponent(cpString), "test" + String.fromCodePoint(i)] + ]) { + test(() => { + const url = urlRecord(scheme); + url[property] = input; + assert_equals(url[property], expected, "property"); + assert_equals(url.href, urlString({ scheme, [property]: expected }), "href"); + }, `Setting ${property} with ${type} ${cpReference} (${scheme}:)`); + } + } + + for (const [type, expectedPart, input] of [ + ["leading", (scheme === "https" ? cpString : encodeURIComponent(cpString)) + "test", String.fromCodePoint(i) + "test"], + ["middle", "te" + (scheme === "https" ? cpString : encodeURIComponent(cpString)) + "st", "te" + String.fromCodePoint(i) + "st"], + ["trailing", "test" + (scheme === "https" ? cpString : encodeURIComponent(cpString)), "test" + String.fromCodePoint(i)] + ]) { + test(() => { + const expected = i === 0x00 ? "host" : stripped ? "test" : expectedPart; + const url = urlRecord(scheme); + url.host = input; + assert_equals(url.host, expected + ":8000", "property"); + assert_equals(url.href, urlString({ scheme, host: expected }), "href"); + }, `Setting host with ${type} ${cpReference} (${scheme}:)`); + + test(() => { + const expected = i === 0x00 ? "host" : stripped ? "test" : expectedPart; + const url = urlRecord(scheme); + url.hostname = input; + assert_equals(url.hostname, expected, "property"); + assert_equals(url.href, urlString({ scheme, host: expected }), "href"); + }, `Setting hostname with ${type} ${cpReference} (${scheme}:)`); + } + + test(() => { + const expected = stripped ? "9000" : "8000"; + const url = urlRecord(scheme); + url.port = String.fromCodePoint(i) + "9000"; + assert_equals(url.port, expected, "property"); + assert_equals(url.href, urlString({ scheme, port: expected }), "href"); + }, `Setting port with leading ${cpReference} (${scheme}:)`); + + test(() => { + const expected = stripped ? "9000" : "90"; + const url = urlRecord(scheme); + url.port = "90" + String.fromCodePoint(i) + "00"; + assert_equals(url.port, expected, "property"); + assert_equals(url.href, urlString({ scheme, port: expected }), "href"); + }, `Setting port with middle ${cpReference} (${scheme}:)`); + + test(() => { + const expected = "9000"; + const url = urlRecord(scheme); + url.port = "9000" + String.fromCodePoint(i); + assert_equals(url.port, expected, "property"); + assert_equals(url.href, urlString({ scheme, port: expected }), "href"); + }, `Setting port with trailing ${cpReference} (${scheme}:)`); + + for (const [property, separator] of [["pathname", "/"], ["search", "?"], ["hash", "#"]]) { + for (const [type, expectedPart, input] of [ + ["leading", encodeURIComponent(cpString) + "test", String.fromCodePoint(i) + "test"], + ["middle", "te" + encodeURIComponent(cpString) + "st", "te" + String.fromCodePoint(i) + "st"], + ["trailing", "test" + encodeURIComponent(cpString), "test" + String.fromCodePoint(i)] + ]) { + test(() => { + const expected = stripped ? "test" : expectedPart; + const url = urlRecord(scheme); + url[property] = input; + assert_equals(url[property], separator + expected, "property"); + assert_equals(url.href, urlString({ scheme, [property]: expected }), "href"); + }, `Setting ${property} with ${type} ${cpReference} (${scheme}:)`); + } + } + } +}