1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

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.
This commit is contained in:
Joel Chippindale 2020-08-17 19:52:45 +01:00 committed by GitHub
parent 68e1ba07d3
commit 1f7d4089f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -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 = {

View file

@ -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 {