Skip to content

Commit 632af80

Browse files
anonriglemire
andcommitted
url: fix url spec compliance issues
Co-authored-by: Daniel Lemire <daniel@lemire.me>
1 parent 9bb104f commit 632af80

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
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"]

0 commit comments

Comments
 (0)