mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix urlSearchParams custom symbol iterator (#2537)
This commit is contained in:
parent
76329cf610
commit
a953190742
2 changed files with 13 additions and 7 deletions
|
@ -12,16 +12,11 @@ export class URLSearchParams {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(init)) {
|
||||
if (Array.isArray(init) || isIterable(init)) {
|
||||
this._handleArrayInitialization(init);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isIterable(init)) {
|
||||
this.params = [...init];
|
||||
return;
|
||||
}
|
||||
|
||||
if (Object(init) !== init) {
|
||||
return;
|
||||
}
|
||||
|
@ -285,7 +280,9 @@ export class URLSearchParams {
|
|||
}
|
||||
}
|
||||
|
||||
private _handleArrayInitialization(init: string[][]): void {
|
||||
private _handleArrayInitialization(
|
||||
init: string[][] | Iterable<[string, string]>
|
||||
): void {
|
||||
// Overload: sequence<sequence<USVString>>
|
||||
for (const tuple of init) {
|
||||
// If pair does not contain exactly two items, then throw a TypeError.
|
||||
|
|
|
@ -227,3 +227,12 @@ test(function urlSearchParamsCustomSymbolIterator(): void {
|
|||
const params1 = new URLSearchParams((params as unknown) as string[][]);
|
||||
assertEquals(params1.get("a"), "b");
|
||||
});
|
||||
|
||||
test(function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void {
|
||||
const params = {};
|
||||
params[Symbol.iterator] = function*(): IterableIterator<[number, number]> {
|
||||
yield [1, 2];
|
||||
};
|
||||
const params1 = new URLSearchParams((params as unknown) as string[][]);
|
||||
assertEquals(params1.get("1"), "2");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue