0
0
Fork 0
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:
Yoshiya Hinosawa 2020-09-02 03:34:41 +09:00 committed by GitHub
parent fee6f79330
commit b3563e8569
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -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));
}
};

View file

@ -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"],