mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 23:28:18 -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:
parent
68e1ba07d3
commit
1f7d4089f9
2 changed files with 4 additions and 4 deletions
cli
|
@ -883,7 +883,7 @@
|
||||||
|
|
||||||
function encodeSearchParam(s) {
|
function encodeSearchParam(s) {
|
||||||
return [...s].map((c) => (charInFormUrlencodedSet(c) ? encodeChar(c) : c))
|
return [...s].map((c) => (charInFormUrlencodedSet(c) ? encodeChar(c) : c))
|
||||||
.join("").replace("%20", "+");
|
.join("").replace(/%20/g, "+");
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__bootstrap.url = {
|
window.__bootstrap.url = {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { unitTest, assert, assertEquals } from "./test_util.ts";
|
import { unitTest, assert, assertEquals } from "./test_util.ts";
|
||||||
|
|
||||||
unitTest(function urlSearchParamsWithSpace(): void {
|
unitTest(function urlSearchParamsWithMultipleSpaces(): void {
|
||||||
const init = { str: "hello world" };
|
const init = { str: "this string has spaces in it" };
|
||||||
const searchParams = new URLSearchParams(init).toString();
|
const searchParams = new URLSearchParams(init).toString();
|
||||||
assertEquals(searchParams, "str=hello+world");
|
assertEquals(searchParams, "str=this+string+has+spaces+in+it");
|
||||||
});
|
});
|
||||||
|
|
||||||
unitTest(function urlSearchParamsWithExclamation(): void {
|
unitTest(function urlSearchParamsWithExclamation(): void {
|
||||||
|
|
Loading…
Reference in a new issue