summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYagiz Nizipli <yagiz@nizipli.com>2023-02-07 14:17:58 -0500
committerDanielle Adams <adamzdanielle@gmail.com>2023-04-11 22:54:52 -0400
commit0c67a7ad573c7976f94d873824c1425183e8dad9 (patch)
treeaf1ed0aa10595d549248ac33972bb0770ffe38cc
parent972bdee8c49989114fb5bd81b651456edb9f83f8 (diff)
downloadnode-new-0c67a7ad573c7976f94d873824c1425183e8dad9.tar.gz
url: fix url spec compliance issues
Co-authored-by: Daniel Lemire <daniel@lemire.me> PR-URL: https://github.com/nodejs/node/pull/46547 Backport-PR-URL: https://github.com/nodejs/node/pull/47435 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>
-rw-r--r--lib/internal/url.js13
-rw-r--r--test/wpt/status/url.json8
-rw-r--r--test/wpt/test-url.js2
3 files changed, 21 insertions, 2 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 2131796b1c..3ed22331cb 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -872,6 +872,19 @@ function update(url, params) {
ctx.search = '?' + serializedParams;
} else {
ctx.search = '';
+
+ // Potentially strip trailing spaces from an opaque path
+ if (ctx.hasOpaquePath && ctx.hash.length === 0) {
+ let length = ctx.pathname.length;
+ while (length > 0 && ctx.pathname.charCodeAt(length - 1) === 32) {
+ length--;
+ }
+
+ // No need to copy the whole string if there is no space at the end
+ if (length !== ctx.pathname.length) {
+ ctx.pathname = ctx.pathname.slice(0, length);
+ }
+ }
}
ctx.href = constructHref(ctx);
}
diff --git a/test/wpt/status/url.json b/test/wpt/status/url.json
index 1c60db0fa7..a0957dccb5 100644
--- a/test/wpt/status/url.json
+++ b/test/wpt/status/url.json
@@ -7,7 +7,13 @@
"skip": "TODO: port from .window.js"
},
"historical.any.js": {
- "requires": ["small-icu"]
+ "requires": ["small-icu"],
+ "fail": {
+ "expected": [
+ "URL: no structured serialize/deserialize support",
+ "URLSearchParams: no structured serialize/deserialize support"
+ ]
+ }
},
"urlencoded-parser.any.js": {
"requires": ["small-icu"]
diff --git a/test/wpt/test-url.js b/test/wpt/test-url.js
index 880153fd8a..1998ea5bf4 100644
--- a/test/wpt/test-url.js
+++ b/test/wpt/test-url.js
@@ -15,6 +15,6 @@ runner.setScriptModifier((obj) => {
});
runner.pretendGlobalThisAs('Window');
runner.setInitScript(`
- globalThis.location = {};
+ globalThis.location ||= {};
`);
runner.runJsTests();