Why a Plus Sign Becomes a Space in Query Parameters
Follow query values through browser, server, and third party; diagnose form encoding, repeated parameters, double encoding, and signed URL byte changes.

A search box receives a+b c, but the results page reads a b c. Start by separating the value in your program from the query string on the wire. Pass raw values to set or append, and serialized query strings to a parser. Mixing those inputs can lose a plus sign or add another layer of percent encoding.
Consider a browser search page that sends a keyword and two tags to a server, which forwards them to a third party. We will follow this chain to find where characters change. The third-party host is an example domain; the local exercise verifies encoding and parsing behavior.
A plus sign depends on the parsing rules
Percent encoding represents bytes as %HH; %2B represents a plus sign. Treating a literal + as a space comes from application/x-www-form-urlencoded. The WHATWG parsing algorithm splits at &, separates each name and value at the first =, replaces literal plus signs with spaces, and then performs percent decoding and UTF-8 decoding. The string constructor of URLSearchParams uses these rules.
One parse produces the following values. The order matters: a plus decoded from %2B does not go back through the earlier replacement step.
| Value on the wire | After one parse | Meaning |
|---|---|---|
+ | One space | A form-encoded space |
%2B | + | A literal plus |
%252B | %2B | A literal percent sign followed by 2B |
%20 | One space | A percent-encoded space |
This does not mean every plus in a URL is a space. The path /a+b and decodeURIComponent("a+b") preserve it. How a query is interpreted depends on the receiving protocol and parser. The address bar is also no substitute for the actual request received by the server.
Build in the browser Parse on the server Rebuild for the third party
const input = "a+b c";
const browserURL = new URL("https://app.example/search");
browserURL.searchParams.set("q", input);
browserURL.searchParams.append("tag", "C++");
browserURL.searchParams.append("tag", "a b");
console.log(browserURL.search);
// ?q=a%2Bb+c&tag=C%2B%2B&tag=a+b
// Server example; a framework query object is often already parsed
const received = new URL(browserURL.href).searchParams;
const q = received.get("q"); // "a+b c"
const tags = received.getAll("tag"); // ["C++", "a b"]
const outbound = new URL("https://api.example/search");
outbound.searchParams.set("q", q);
for (const tag of tags) outbound.searchParams.append("tag", tag);
console.assert(outbound.search === browserURL.search);
console.assert(new URL(outbound.href).searchParams.get("q") === input);

The literal plus survives both transmission boundaries.
“Once” means once per parsing or serialization boundary, not one API call for the entire system. If the framework has already parsed q, use that value directly. Do not call decodeURIComponent(q) again or construct new URLSearchParams("q=" + q): the latter treats plus signs inside the value as query syntax.
Conversely, set("q", encodeURIComponent(input)) treats encoded text as a raw value and produces q=a%252Bb%2520c. One parse on the receiving end returns a%2Bb%20c. If the intended input is literally %2B, producing %252B is correct. Establish the intended business value before diagnosing extra encoding.
Read a complete URL with new URL(address).searchParams. new URLSearchParams(address) does not identify a host, path, or fragment; it processes the entire input as query syntax. The MDN examples explain these two entry points.
Agree on Base64 and repeated parameters
Standard Base64 can contain +, /, and =. Concatenating E+AXQB+A into token=E+AXQB+A yields E AXQB A after form parsing. set("token", token) produces token=E%2BAXQB%2BA, allowing the receiver to recover the original. If the protocol specifies Base64url, follow its alphabet and padding convention; do not change token formats merely to avoid plus signs.
Repeated parameters need a shared contract too. get("tag") returns the first value, getAll("tag") returns all of them, append adds an entry, and set replaces matching entries with one value. A server framework may return the last entry, an array, or an error. Browser API behavior does not establish the server contract. Check the count for single-value fields; preserve arrays and order for tags when required. Forward them with append, rather than collapsing duplicates through Object.fromEntries.
Signed URLs depend on the agreed bytes
Equal parsed values need not produce equal query strings. Here, sort triggers serialization even though the parameter order is already sorted:
const u = new URL("https://cdn.example/image?q=a%20b~&tag=1&tag=2");
const original = u.search;
u.searchParams.sort();
console.log(original); // ?q=a%20b~&tag=1&tag=2
console.log(u.search); // ?q=a+b%7E&tag=1&tag=2
The space changes from %20 to +, and ~ becomes %7E. If a signature covers the original query bytes, its input changes; a local HMAC assertion also produces different digests. Real schemes may define parameter sorting, duplicate order, escaping, letter case, and whether the signature field is excluded. Follow the provider’s canonicalization rules or SDK. Preserve a received signed URL in its complete form. If it must change, regenerate the signature according to that protocol. Equal parsed values do not prove a signature remains valid.
Find the first changed boundary
Compare the input value, the browser’s actual request query, the server’s raw query and parsed values, and the outgoing third-party query in order. Keep tokens and signatures out of logs. For harmless test values, JSON.stringify makes spaces visible. At the first difference, determine whether the code expects a value or serialized text.
Run these assertions in Node or a browser console:
console.assert(new URLSearchParams("q=a+b").get("q") === "a b");
console.assert(new URLSearchParams("q=a%2Bb").get("q") === "a+b");
console.assert(new URLSearchParams("q=%252B").get("q") === "%2B");
const p = new URLSearchParams();
p.set("q", "a+b c");
console.assert(p.toString() === "q=a%2Bb+c");
console.assert(new URLSearchParams(p.toString()).get("q") === "a+b c");
console.assert(decodeURIComponent("a+b") === "a+b");
These results pin down parsing, literal plus signs, and round-trip values separately. Once the integration is connected, use the same test values against the real framework and third party, paying particular attention to duplicate parameters and signature rules.