From 8578ed4e7fcbddcbfb87368529f629ce1aebfebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=B7=E6=B8=A1?= Date: Thu, 25 Apr 2019 21:29:50 +0800 Subject: [PATCH] `URLSearchParams` deleting appended multiple (#2201) --- js/url_search_params.ts | 3 ++- js/url_search_params_test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/js/url_search_params.ts b/js/url_search_params.ts index 1b4461ed23..9f4621b7b3 100644 --- a/js/url_search_params.ts +++ b/js/url_search_params.ts @@ -32,7 +32,7 @@ export class URLSearchParams { */ append(name: string, value: string): void { requiredArguments("URLSearchParams.append", arguments.length, 2); - this.params.push([String(name), value]); + this.params.push([String(name), String(value)]); } /** Deletes the given search parameter and its associated value, @@ -112,6 +112,7 @@ export class URLSearchParams { // set the value of the first such name-value pair to value // and remove the others. name = String(name); + value = String(value); let found = false; let i = 0; while (i < this.params.length) { diff --git a/js/url_search_params_test.ts b/js/url_search_params_test.ts index 9b20b3b75a..8da11382fa 100644 --- a/js/url_search_params_test.ts +++ b/js/url_search_params_test.ts @@ -182,3 +182,17 @@ test(function urlSearchParamsAppendArgumentsCheck(): void { } ); }); + +// ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-delete.any.js +test(function urlSearchParamsDeletingAppendedMultiple(): void { + const params = new URLSearchParams(); + params.append("first", (1 as unknown) as string); + assert(params.has("first")); + assertEquals(params.get("first"), "1"); + params.delete("first"); + assertEquals(params.has("first"), false); + params.append("first", (1 as unknown) as string); + params.append("first", (10 as unknown) as string); + params.delete("first"); + assertEquals(params.has("first"), false); +});