Skip to content

Commit

Permalink
url: fix url spec compliance issues
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and danielleadams committed Apr 12, 2023
1 parent 972bdee commit 0c67a7a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 7 additions & 1 deletion test/wpt/status/url.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion test/wpt/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ runner.setScriptModifier((obj) => {
});
runner.pretendGlobalThisAs('Window');
runner.setInitScript(`
globalThis.location = {};
globalThis.location ||= {};
`);
runner.runJsTests();

0 comments on commit 0c67a7a

Please sign in to comment.