Permalink
Browse files

url: fix URL query update if searchParams changes

If searchParams becomes empty, query must be set to null.
Add missing update of context flags.

Fixes: #10480
PR-URL: #10486
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
targos committed Dec 28, 2016
1 parent db18dd8 commit b465cd07fee443ef23b55d05b838379b4069bfa4
Showing with 21 additions and 1 deletion.
  1. +9 −1 lib/internal/url.js
  2. +12 −0 test/parallel/test-whatwg-url-searchparams-delete.js
@@ -593,7 +593,15 @@ function update(url, params) {
if (!url)
return;
url[context].query = params.toString();
const ctx = url[context];
const serializedParams = params.toString();
if (serializedParams) {
ctx.query = serializedParams;
ctx.flags |= binding.URL_FLAGS_HAS_QUERY;
} else {
ctx.query = null;
ctx.flags &= ~binding.URL_FLAGS_HAS_QUERY;
}
}
function getSearchParamPairs(target) {
@@ -42,3 +42,15 @@ params.append('first', 10);
params.delete('first');
assert.strictEqual(false, params.has('first'),
'Search params object has no "first" name');
// https://github.com/nodejs/node/issues/10480
// Emptying searchParams should correctly update url's query
{
const url = new URL('http://domain?var=1&var=2&var=3');
for (const param of url.searchParams.keys()) {
url.searchParams.delete(param);
}
assert.strictEqual(url.searchParams.toString(), '');
assert.strictEqual(url.search, '');
assert.strictEqual(url.href, 'http://domain/');
}

0 comments on commit b465cd0

Please sign in to comment.