mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(URLSearchParams): fix handling of + character (#7314)
This commit is contained in:
parent
fee6f79330
commit
b3563e8569
2 changed files with 12 additions and 1 deletions
|
@ -14,6 +14,10 @@
|
|||
return sendSync("op_domain_to_ascii", { domain, beStrict });
|
||||
}
|
||||
|
||||
function decodeSearchParam(p) {
|
||||
return decodeURIComponent(p.replace(/\+/g, " "));
|
||||
}
|
||||
|
||||
const urls = new WeakMap();
|
||||
|
||||
class URLSearchParams {
|
||||
|
@ -63,7 +67,7 @@
|
|||
const position = pair.indexOf("=");
|
||||
const name = pair.slice(0, position === -1 ? pair.length : position);
|
||||
const value = pair.slice(name.length + 1);
|
||||
this.#append(decodeURIComponent(name), decodeURIComponent(value));
|
||||
this.#append(decodeSearchParam(name), decodeSearchParam(value));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -48,6 +48,13 @@ unitTest(function urlSearchParamsInitString(): void {
|
|||
);
|
||||
});
|
||||
|
||||
unitTest(function urlSearchParamsInitStringWithPlusCharacter(): void {
|
||||
const init = "q=a+b";
|
||||
const searchParams = new URLSearchParams(init);
|
||||
assertEquals(searchParams.toString(), init);
|
||||
assertEquals(searchParams.get("q"), "a b");
|
||||
});
|
||||
|
||||
unitTest(function urlSearchParamsInitIterable(): void {
|
||||
const init = [
|
||||
["a", "54"],
|
||||
|
|
Loading…
Add table
Reference in a new issue