Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
25 changes: 13 additions & 12 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ function onParseSearchComplete(flags, protocol, username, password,
if (flags & binding.URL_FLAGS_FAILED)
return;
const ctx = this[context];
if (query) {
ctx.query = query;
ctx.flags |= binding.URL_FLAGS_HAS_QUERY;
} else {
ctx.flags &= ~binding.URL_FLAGS_HAS_QUERY;
}
ctx.query = query;
}

function onParseHashComplete(flags, protocol, username, password,
Expand Down Expand Up @@ -487,13 +482,15 @@ Object.defineProperties(URL.prototype, {
if (!search) {
ctx.query = null;
ctx.flags &= ~binding.URL_FLAGS_HAS_QUERY;
this[searchParams][searchParams] = {};
return;
} else {
if (search[0] === '?') search = search.slice(1);
ctx.query = '';
ctx.flags |= binding.URL_FLAGS_HAS_QUERY;
if (search) {
binding.parse(search, binding.kQuery, null, ctx,
onParseSearchComplete.bind(this));
}
}
if (search[0] === '?') search = search.slice(1);
ctx.query = '';
binding.parse(search, binding.kQuery, null, ctx,
onParseSearchComplete.bind(this));
initSearchParams(this[searchParams], search);
}
},
Expand Down Expand Up @@ -614,6 +611,10 @@ function update(url, params) {
// Reused by the URL parse function invoked by
// the href setter, and the URLSearchParams constructor
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just get rid of the comment now, or mention search in it.

function initSearchParams(url, init) {
if (!init) {
url[searchParams] = [];
return;
}
url[searchParams] = getParamsFromObject(querystring.parse(init));
}

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-whatwg-url-searchparams.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ assert(sp.has('a'));
assert.strictEqual(sp.get('a'), '[object Object]');
sp.delete('a');
assert(!sp.has('a'));

m.search = '';
assert.strictEqual(sp.toString(), '');

values.forEach((i) => sp.append('a', i));
assert(sp.has('a'));
assert.strictEqual(sp.getAll('a').length, 6);
Expand Down