mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
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:
1 parent
915e3e2f42
commit
d5be94e820
2 files changed
+9
-3
No files matched your search
+2
-2
@@ -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']])
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user