Skip to content

Commit 0c67a7a

Browse files
anonriglemire
authored andcommitted
url: fix url spec compliance issues
Co-authored-by: Daniel Lemire <[email protected]> PR-URL: #46547 Backport-PR-URL: #47435 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 972bdee commit 0c67a7a

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/internal/url.js

+13
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,19 @@ function update(url, params) {
872872
ctx.search = '?' + serializedParams;
873873
} else {
874874
ctx.search = '';
875+
876+
// Potentially strip trailing spaces from an opaque path
877+
if (ctx.hasOpaquePath && ctx.hash.length === 0) {
878+
let length = ctx.pathname.length;
879+
while (length > 0 && ctx.pathname.charCodeAt(length - 1) === 32) {
880+
length--;
881+
}
882+
883+
// No need to copy the whole string if there is no space at the end
884+
if (length !== ctx.pathname.length) {
885+
ctx.pathname = ctx.pathname.slice(0, length);
886+
}
887+
}
875888
}
876889
ctx.href = constructHref(ctx);
877890
}

test/wpt/status/url.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"skip": "TODO: port from .window.js"
88
},
99
"historical.any.js": {
10-
"requires": ["small-icu"]
10+
"requires": ["small-icu"],
11+
"fail": {
12+
"expected": [
13+
"URL: no structured serialize/deserialize support",
14+
"URLSearchParams: no structured serialize/deserialize support"
15+
]
16+
}
1117
},
1218
"urlencoded-parser.any.js": {
1319
"requires": ["small-icu"]

test/wpt/test-url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ runner.setScriptModifier((obj) => {
1515
});
1616
runner.pretendGlobalThisAs('Window');
1717
runner.setInitScript(`
18-
globalThis.location = {};
18+
globalThis.location ||= {};
1919
`);
2020
runner.runJsTests();

0 commit comments

Comments
 (0)