提交 a9531907 编写于 作者: 迷渡's avatar 迷渡 提交者: Ryan Dahl

fix urlSearchParams custom symbol iterator (#2537)

上级 76329cf6
......@@ -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");
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册