Skip to content

Commit

Permalink
check URLSearchParams.constructor's params (denoland#2488)
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac authored and ry committed Jun 10, 2019
1 parent a115340 commit 5871d22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions js/url_search_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
13 changes: 13 additions & 0 deletions js/url_search_params_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5871d22

Please sign in to comment.