diff --git a/lib/internal/url.js b/lib/internal/url.js index a1b61a4c1127c9..25cf8a79e7617b 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -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); } diff --git a/test/wpt/status/url.json b/test/wpt/status/url.json index 1c60db0fa7e715..a0957dccb53c73 100644 --- a/test/wpt/status/url.json +++ b/test/wpt/status/url.json @@ -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"] diff --git a/test/wpt/test-url.js b/test/wpt/test-url.js index 880153fd8a2d63..1998ea5bf43798 100644 --- a/test/wpt/test-url.js +++ b/test/wpt/test-url.js @@ -15,6 +15,6 @@ runner.setScriptModifier((obj) => { }); runner.pretendGlobalThisAs('Window'); runner.setInitScript(` - globalThis.location = {}; + globalThis.location ||= {}; `); runner.runJsTests();