Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: fix handling of ? in URLSearchParams creation #11372

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ function onParseComplete(flags, protocol, username, password,
ctx.query = query;
ctx.fragment = fragment;
ctx.host = host;
if (this[searchParams]) { // invoked from href setter
initSearchParams(this[searchParams], query);
} else {
this[searchParams] = new URLSearchParams(query);
if (!this[searchParams]) { // invoked from URL constructor
this[searchParams] = new URLSearchParams();
this[searchParams][context] = this;
}
this[searchParams][context] = this;
initSearchParams(this[searchParams], query);
}

// Reused by URL constructor and URL#href setter.
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-whatwg-url-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,22 @@ function runURLSearchParamTests() {

// And in the other direction, altering searchParams propagates
// back to 'search'.
// searchParams.append('i', ' j ')
searchParams.append('i', ' j ')
// assert_equals(url.search, '?e=f&g=h&i=+j+')
// assert_equals(url.searchParams.toString(), 'e=f&g=h&i=+j+')
// assert_equals(searchParams.get('i'), ' j ')
assert_equals(searchParams.get('i'), ' j ')

// searchParams.set('e', 'updated')
searchParams.set('e', 'updated')
// assert_equals(url.search, '?e=updated&g=h&i=+j+')
// assert_equals(searchParams.get('e'), 'updated')
assert_equals(searchParams.get('e'), 'updated')

// var url2 = bURL('http://example.org/file??a=b&c=d')
// assert_equals(url2.search, '??a=b&c=d')
// assert_equals(url2.searchParams.toString(), '%3Fa=b&c=d')
var url2 = bURL('http://example.org/file??a=b&c=d')
assert_equals(url2.search, '??a=b&c=d')
assert_equals(url2.searchParams.toString(), '%3Fa=b&c=d')

// url2.href = 'http://example.org/file??a=b'
// assert_equals(url2.search, '??a=b')
// assert_equals(url2.searchParams.toString(), '%3Fa=b')
url2.href = 'http://example.org/file??a=b'
assert_equals(url2.search, '??a=b')
assert_equals(url2.searchParams.toString(), '%3Fa=b')
}, 'URL.searchParams and URL.search setters, update propagation')
}
runURLSearchParamTests()
Expand Down