mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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: https://github.com/nodejs/node/issues/10480 PR-URL: https://github.com/nodejs/node/pull/10486 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
db18dd8356
commit
b465cd07fe
@ -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/');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user