diff options
author | 迷渡 <justjavac@gmail.com> | 2019-06-10 19:20:59 +0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-10 07:20:59 -0400 |
commit | 5871d22d9b1f99a4735ff7b4e2dcca977795aa74 (patch) | |
tree | 4eeb9dabb651058cddb4bc4cd30aee043ff0dfee /js | |
parent | a115340288d974f141cceb16faac71914402c445 (diff) |
check `URLSearchParams.constructor`'s params (#2488)
Diffstat (limited to 'js')
-rw-r--r-- | js/url_search_params.ts | 10 | ||||
-rw-r--r-- | js/url_search_params_test.ts | 13 |
2 files changed, 18 insertions, 5 deletions
diff --git a/js/url_search_params.ts b/js/url_search_params.ts index 1d9aa43b3..d9c4e59ab 100644 --- a/js/url_search_params.ts +++ b/js/url_search_params.ts @@ -280,11 +280,11 @@ export class URLSearchParams { // Overload: sequence<sequence<USVString>> for (const tuple of init) { // If pair does not contain exactly two items, then throw a TypeError. - requiredArguments( - "URLSearchParams.constructor tuple array argument", - tuple.length, - 2 - ); + if (tuple.length !== 2) { + throw new TypeError( + "URLSearchParams.constructor tuple array argument must only contain pair elements" + ); + } this.append(tuple[0], tuple[1]); } } diff --git a/js/url_search_params_test.ts b/js/url_search_params_test.ts index 0bce1166c..d37b55497 100644 --- a/js/url_search_params_test.ts +++ b/js/url_search_params_test.ts @@ -147,6 +147,19 @@ test(function urlSearchParamsShouldThrowTypeError(): void { } assertEquals(hasThrown, 2); + + try { + new URLSearchParams([["1", "2", "3"]]); + hasThrown = 1; + } catch (err) { + if (err instanceof TypeError) { + hasThrown = 2; + } else { + hasThrown = 3; + } + } + + assertEquals(hasThrown, 2); }); test(function urlSearchParamsAppendArgumentsCheck(): void { |