Skip to content

Commit

Permalink
fix(URLSearchParams): fix handling of + character (denoland#7314)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Sep 1, 2020
1 parent fee6f79 commit b3563e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cli/rt/11_url.js
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
};

Expand Down
7 changes: 7 additions & 0 deletions cli/tests/unit/url_search_params_test.ts
Expand Up @@ -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"],
Expand Down

0 comments on commit b3563e8

Please sign in to comment.