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>
  • Loading branch information
anonrig and lemire committed Feb 14, 2023
1 parent 9bb104f commit 7d96dc6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,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

0 comments on commit 7d96dc6

Please sign in to comment.