diff --git a/src/http/fetch_request.ts b/src/http/fetch_request.ts index 0dcc206f2..404429408 100644 --- a/src/http/fetch_request.ts +++ b/src/http/fetch_request.ts @@ -55,13 +55,22 @@ export class FetchRequest { } get url() { - const url = this.location.absoluteURL - const query = this.params.toString() - if (this.isIdempotent && query.length) { - return [url, query].join(url.includes("?") ? "&" : "?") - } else { - return url + const url = new URL(this.location.absoluteURL) + + if (this.isIdempotent) { + const currentUrl = new URL(window.location.href) + + for (const [ key, value ] of this.params) { + if (currentUrl.searchParams.has(key)) { + currentUrl.searchParams.delete(key) + url.searchParams.set(key, value) + } else { + url.searchParams.append(key, value) + } + } } + + return url.href } get params() { diff --git a/src/tests/fixtures/form.html b/src/tests/fixtures/form.html index c4c566f43..3b36fae7b 100644 --- a/src/tests/fixtures/form.html +++ b/src/tests/fixtures/form.html @@ -26,7 +26,24 @@ +
+