Skip to content

Commit 0c67a7a

Browse files
anonriglemire
authored andcommitted
url: fix url spec compliance issues
Co-authored-by: Daniel Lemire <daniel@lemire.me> PR-URL: #46547 Backport-PR-URL: #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>
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy