summaryrefslogtreecommitdiff
path: root/js/url_search_params.ts
diff options
context:
space:
mode:
author迷渡 <justjavac@gmail.com>2019-04-30 07:45:20 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-04-29 16:45:20 -0700
commit4dcdd881553047efc90e0b3d532206225c1ca5fb (patch)
treeb4392ad2333d81d4299a205ddb67005f203d2849 /js/url_search_params.ts
parent636827a1d52285642eeb375781abe941c79a07f0 (diff)
removes ? from URL when deleting all params (#2217)
Diffstat (limited to 'js/url_search_params.ts')
-rw-r--r--js/url_search_params.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/js/url_search_params.ts b/js/url_search_params.ts
index 13b272476..1d9aa43b3 100644
--- a/js/url_search_params.ts
+++ b/js/url_search_params.ts
@@ -1,8 +1,10 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+import { URL } from "./url";
import { requiredArguments } from "./util";
export class URLSearchParams {
private params: Array<[string, string]> = [];
+ private url: URL | null = null;
constructor(init: string | string[][] | Record<string, string> = "") {
if (typeof init === "string") {
@@ -30,6 +32,20 @@ export class URLSearchParams {
}
}
+ private updateSteps(): void {
+ if (this.url === null) {
+ return;
+ }
+
+ let query: string | null = this.toString();
+ if (query === "") {
+ query = null;
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (this.url as any)._parts.query = query;
+ }
+
/** Appends a specified key/value pair as a new search parameter.
*
* searchParams.append('name', 'first');
@@ -56,6 +72,7 @@ export class URLSearchParams {
i++;
}
}
+ this.updateSteps();
}
/** Returns all the values associated with a given search parameter