diff --git a/js/url_search_params.ts b/js/url_search_params.ts index 9f4621b7b3..13b272476b 100644 --- a/js/url_search_params.ts +++ b/js/url_search_params.ts @@ -19,6 +19,11 @@ export class URLSearchParams { return; } + if (init instanceof URLSearchParams) { + this.params = init.params; + return; + } + // Overload: record for (const key of Object.keys(init)) { this.append(key, init[key]); diff --git a/js/url_search_params_test.ts b/js/url_search_params_test.ts index 8da11382fa..0bce1166c5 100644 --- a/js/url_search_params_test.ts +++ b/js/url_search_params_test.ts @@ -22,6 +22,14 @@ test(function urlSearchParamsInitRecord(): void { assertEquals(searchParams.toString(), "a=54&b=true"); }); +test(function urlSearchParamsInit(): void { + const params1 = new URLSearchParams("a=b"); + assertEquals(params1.toString(), "a=b"); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const params2 = new URLSearchParams(params1 as any); + assertEquals(params2.toString(), "a=b"); +}); + test(function urlSearchParamsAppendSuccess(): void { const searchParams = new URLSearchParams(); searchParams.append("a", "true");