url: fix URLSearchParams(null) to prudce null= per spec

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63782
Fixes: https://github.com/nodejs/node/issues/63559
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Marco authored and Antoine du Hamel committed 2026-07-30 13:51:34 +02:00
1 parent 915e3e2f42
commit d5be94e820
2 files changed
+9 -3

No files matched your search

+2 -2
View File
@@ -337,9 +337,9 @@ class URLSearchParams {
constructor(init = undefined) {
markTransferMode(this, false, false);
if (init == null) {
if (init === undefined) {
// Do nothing
} else if (typeof init === 'object' || typeof init === 'function') {
} else if (init !== null && (typeof init === 'object' || typeof init === 'function')) {
const method = init[SymbolIterator];
if (method === this[SymbolIterator] && #searchParams in init) {
// While the spec does not have this branch, we can use it as a
@@ -28,8 +28,14 @@ function makeIterableFunc(array) {
let params;
params = new URLSearchParams(undefined);
assert.strictEqual(params.toString(), '');
// Per WebIDL union resolution, null is coerced to the USVString "null".
// Refs: https://url.spec.whatwg.org/#interface-urlsearchparams
params = new URLSearchParams(null);
assert.strictEqual(params.toString(), '');
assert.strictEqual(params.toString(), 'null=');
params = new URLSearchParams(false);
assert.strictEqual(params.toString(), 'false=');
params = new URLSearchParams(0);
assert.strictEqual(params.toString(), '0=');
params = new URLSearchParams(
makeIterableFunc([['key', 'val'], ['key2', 'val2']])
);