Applied code suggestions
authorMarcel Werk <burntime@woltlab.com>
Sat, 11 Dec 2021 10:43:18 +0000 (11:43 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 11 Dec 2021 10:43:18 +0000 (11:43 +0100)
ts/WoltLabSuite/Core/Ui/Search/Extended.ts
ts/WoltLabSuite/Core/Ui/Search/Page.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Extended.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search/Page.js

index 227191ed11124ec781a7e1a0b6eac98d0888d889..b355a8afd289350bdc608d571a940fc51bb052e5 100644 (file)
@@ -98,13 +98,15 @@ export class UiSearchExtended {
 
   private updateQueryString(): void {
     const url = new URL(this.form.action);
+    url.search += url.search !== "" ? "&" : "?";
 
+    const parameters: string[][] = [];
     new FormData(this.form).forEach((value, key) => {
-      if (value.toString()) {
-        url.search += url.search !== "" ? "&" : "?";
-        url.search += encodeURIComponent(key) + "=" + encodeURIComponent(value.toString());
+      if (value.toString().trim()) {
+        parameters.push([key, value.toString().trim()]);
       }
     });
+    url.search += new URLSearchParams(parameters);
 
     window.history.replaceState({}, document.title, url.toString());
   }
index 3c6623a0706a8f55ad393ed0cb3d89b974d6062f..34e2bc77f8ed31901d6fc9ec92774f95cfcc769f 100644 (file)
@@ -108,11 +108,6 @@ export function init(objectType: string): void {
 function submit(form: HTMLFormElement, input: HTMLInputElement): void {
   const url = new URL(form.action);
   url.search += url.search !== "" ? "&" : "?";
-  url.search += "q=" + encodeURIComponent(input.value.trim());
-
-  parameters.forEach((value, key) => {
-    url.search += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(value);
-  });
-
+  url.search += new URLSearchParams([["q", input.value.trim()], ...Array.from(parameters)]).toString();
   window.location.href = url.toString();
 }
index abf1da089cc0433e59cd8e73960809f5f269c539..c1907f7727c03694e95c4adc9ce9812ce53e84a5 100644 (file)
@@ -69,12 +69,14 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Date/Picker", "../..
         }
         updateQueryString() {
             const url = new URL(this.form.action);
+            url.search += url.search !== "" ? "&" : "?";
+            const parameters = [];
             new FormData(this.form).forEach((value, key) => {
-                if (value.toString()) {
-                    url.search += url.search !== "" ? "&" : "?";
-                    url.search += encodeURIComponent(key) + "=" + encodeURIComponent(value.toString());
+                if (value.toString().trim()) {
+                    parameters.push([key, value.toString().trim()]);
                 }
             });
+            url.search += new URLSearchParams(parameters);
             window.history.replaceState({}, document.title, url.toString());
         }
         getFormData() {
index 6c91855d044a95bc8ed082f517eef29d4eb24b23..a9c7d4c4af9f5dfa1731b9c632edaadf4b46b2a9 100644 (file)
@@ -88,10 +88,7 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Traverse", "../.
     function submit(form, input) {
         const url = new URL(form.action);
         url.search += url.search !== "" ? "&" : "?";
-        url.search += "q=" + encodeURIComponent(input.value.trim());
-        parameters.forEach((value, key) => {
-            url.search += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(value);
-        });
+        url.search += new URLSearchParams([["q", input.value.trim()], ...Array.from(parameters)]).toString();
         window.location.href = url.toString();
     }
 });