ensure opaque paths always roundtrip in URL polyfill

https://github.com/whatwg/url/pull/844
This commit is contained in:
Denis Pushkarev
2026-04-13 11:31:41 +03:00
parent b1b9f0f8c3
commit f9bca07318
4 changed files with 26 additions and 1 deletions
+1
View File
@@ -1,5 +1,6 @@
# Changelog
### Unreleased
- Ensure opaque paths always roundtrip in URL polyfill (still without adding to feature detection), [whatwg/url#844](https://github.com/whatwg/url/pull/844)
- Fixed possible crash on some keys in `Symbol.for`
- Some `get-iterator` / `get-iterator-method` fixes
- Fixed `String.prototype.{ match, search }` polyfills conversion order
@@ -749,7 +749,11 @@ URLState.prototype = {
url.fragment = '';
state = FRAGMENT;
} else if (chr !== EOF) {
url.path[0] += percentEncode(chr, C0ControlPercentEncodeSet);
if (chr === ' ') {
url.path[0] += codePoints[pointer + 1] === '?' || codePoints[pointer + 1] === '#' ? '%20' : ' ';
} else {
url.path[0] += percentEncode(chr, C0ControlPercentEncodeSet);
}
} break;
case QUERY:
+10
View File
@@ -536,6 +536,16 @@ QUnit.test('URL#search', assert => {
// eslint-disable-next-line no-script-url -- safe
assert.same(new URL('javascript:void 0').pathname, 'void 0', 'space preserved in opaque pathname');
// space before query or fragment in opaque paths should be percent-encoded
/*
assert.same(new URL('x:path ?query').href, 'x:path%20?query', 'space before query in opaque path encoded as %20');
assert.same(new URL('x:path ?query').search, '?query', 'query parsed after encoded space');
assert.same(new URL('x:path #frag').href, 'x:path%20#frag', 'space before fragment in opaque path encoded as %20');
assert.same(new URL('x:path #frag').hash, '#frag', 'fragment parsed after encoded space');
assert.same(new URL('x:a b c ?d').pathname, 'a b c%20', 'only space before query encoded');
assert.same(new URL('x:a b c #d').pathname, 'a b c%20', 'only space before fragment encoded');
*/
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/?');
assert.same(url.search, '');
+10
View File
@@ -537,6 +537,16 @@ QUnit.test('URL#search', assert => {
// eslint-disable-next-line no-script-url -- safe
assert.same(new URL('javascript:void 0').pathname, 'void 0', 'space preserved in opaque pathname');
// space before query or fragment in opaque paths should be percent-encoded
/*
assert.same(new URL('x:path ?query').href, 'x:path%20?query', 'space before query in opaque path encoded as %20');
assert.same(new URL('x:path ?query').search, '?query', 'query parsed after encoded space');
assert.same(new URL('x:path #frag').href, 'x:path%20#frag', 'space before fragment in opaque path encoded as %20');
assert.same(new URL('x:path #frag').hash, '#frag', 'fragment parsed after encoded space');
assert.same(new URL('x:a b c ?d').pathname, 'a b c%20', 'only space before query encoded');
assert.same(new URL('x:a b c #d').pathname, 'a b c%20', 'only space before fragment encoded');
*/
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/?');
assert.same(url.search, '');