Skip to content

Commit 9d55a5e

Browse files
anonriglemire
authored andcommittedMar 13, 2023
url: fix url spec compliance issues
Co-authored-by: Daniel Lemire <daniel@lemire.me> PR-URL: #46547 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>
1 parent 95bbd0f commit 9d55a5e

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
@@ -864,6 +864,19 @@ function update(url, params) {
864864
ctx.search = '?' + serializedParams;
865865
} else {
866866
ctx.search = '';
867+
868+
// Potentially strip trailing spaces from an opaque path
869+
if (ctx.hasOpaquePath && ctx.hash.length === 0) {
870+
let length = ctx.pathname.length;
871+
while (length > 0 && ctx.pathname.charCodeAt(length - 1) === 32) {
872+
length--;
873+
}
874+
875+
// No need to copy the whole string if there is no space at the end
876+
if (length !== ctx.pathname.length) {
877+
ctx.pathname = ctx.pathname.slice(0, length);
878+
}
879+
}
867880
}
868881
ctx.href = constructHref(ctx);
869882
}

‎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)
Please sign in to comment.