summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Chippindale <joel@joelchippindale.com>2020-08-17 19:52:45 +0100
committerGitHub <noreply@github.com>2020-08-17 14:52:45 -0400
commit1f7d4089f9125cec9fa0c0ada55a3d50a8cdfd0d (patch)
tree7e27a649cba4ac278e67c85f8e26b96df2648952
parent68e1ba07d3d6716ff651fe6d379b46fb61253a1d (diff)
Fix handling of multiple spaces in URLSearchParams (#7068)
This ensures that all spaces are set to be "+" in the string rather than just the first and brings deno into line with how browsers handle spaces in URLSearchParams, see #7001.
-rw-r--r--cli/rt/11_url.js2
-rw-r--r--cli/tests/unit/url_search_params_test.ts6
2 files changed, 4 insertions, 4 deletions
diff --git a/cli/rt/11_url.js b/cli/rt/11_url.js
index cb42e22c7..a7200f11c 100644
--- a/cli/rt/11_url.js
+++ b/cli/rt/11_url.js
@@ -883,7 +883,7 @@
function encodeSearchParam(s) {
return [...s].map((c) => (charInFormUrlencodedSet(c) ? encodeChar(c) : c))
- .join("").replace("%20", "+");
+ .join("").replace(/%20/g, "+");
}
window.__bootstrap.url = {
diff --git a/cli/tests/unit/url_search_params_test.ts b/cli/tests/unit/url_search_params_test.ts
index 7698ef1ce..c20db56dd 100644
--- a/cli/tests/unit/url_search_params_test.ts
+++ b/cli/tests/unit/url_search_params_test.ts
@@ -1,10 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert, assertEquals } from "./test_util.ts";
-unitTest(function urlSearchParamsWithSpace(): void {
- const init = { str: "hello world" };
+unitTest(function urlSearchParamsWithMultipleSpaces(): void {
+ const init = { str: "this string has spaces in it" };
const searchParams = new URLSearchParams(init).toString();
- assertEquals(searchParams, "str=hello+world");
+ assertEquals(searchParams, "str=this+string+has+spaces+in+it");
});
unitTest(function urlSearchParamsWithExclamation(): void {