Take one perfectly ordinary query string:
https://api.example.com/lookup?phone=+15551234567
Ask two decoders what the phone parameter contains, and you will get two different answers. A decoder following the application/x-www-form-urlencoded convention — the one most web frameworks apply to query strings — reports a leading space in place of the plus. A decoder following the generic URI grammar of RFC 3986 reports the plus intact. Nothing was corrupted in transit and nobody made a typo. The same byte sequence legitimately decodes two ways, and which answer you get depends on which layer does the decoding.
This ambiguity is one of the oldest quirks in web infrastructure, and it produces a steady trickle of production bugs: phone numbers that lose their international prefix, tokens that fail signature checks, search queries that come back wrong in ways nobody can reproduce. This guide explains where the split came from, walks through the failure modes, and lays out a decoding workflow plus a set of encoding defaults that make the ambiguity harmless.
Two conventions, one character
The form-urlencoded tradition
The older convention predates the modern URL standards. When an HTML form is submitted with the default application/x-www-form-urlencoded media type, the browser serializes field names and values into a query string. A space is illegal in a URL, so the format needs a way to spell one. Percent-encoding already existed — %20 — but early form encoding picked a shortcut: a literal + means space. The choice made form output slightly more readable, and it has stuck around for decades. Every HTML form submitted via GET, every URLSearchParams serialization in JavaScript, PHP's urlencode(), and Java's URLEncoder all emit spaces as +, and their matching decoders all read + back as a space.
The generic URI grammar
RFC 3986, the document that defines what a URI is, deliberately declines to give + any special meaning. In its grammar, + is a sub-delimiter: a character that may appear raw inside a component and is free for individual schemes and APIs to define as they see fit. Some APIs use it to join repeated values. Most treat it simply as data. Under this grammar, a plus in a query value means a plus — a decoder should not touch it, and the only thing that collapses into a space is an explicit %20.
Neither reading is wrong. The form convention is a self-consistent pair: emit + for space, decode + as space, and values round-trip cleanly. The generic grammar is likewise self-consistent: plus is plus, %20 is space, and values round-trip cleanly. The bug appears when a producer speaking one convention hands its output to a consumer speaking the other. Then a plus written as data gets decoded as a space — or, in the rarer and more confusing direction, a plus written to mean a space survives as a literal plus.
The same string, decoded two ways
The table below shows how a handful of raw query-string fragments decode under each convention. The middle column is what a form-style parser produces; the right column is what a generic percent-decoder produces.
| Raw query string | Form-style decoding | Generic (RFC 3986) decoding |
|---|---|---|
q=a+b | a b | a+b |
q=a%20b | a b | a b |
q=a%2Bb | a+b | a+b |
phone=+15551234567 | (space)15551234567 | +15551234567 |
phone=%2B15551234567 | +15551234567 | +15551234567 |
sig=4f+9a== | 4f 9a== | 4f+9a== |
q=C%2B%2B | C++ | C++ |
Notice the pattern: percent-escapes decode identically under both conventions. %2B is a plus everywhere and %20 is a space everywhere. The only divergence is a bare plus. That makes the ambiguity almost entirely avoidable on the producing side — and entirely a matter of context on the receiving side.
It is tempting to ask why the web never standardized on one reading. The answer is inertia on both sides. Form decoding is load-bearing for billions of legacy forms and server endpoints that predate any alternative, while the generic grammar is load-bearing for every URL that is not a form result — and both populations are enormous. Standards efforts have consistently chosen compatibility over cleanup: the WHATWG URL specification describes the form-urlencoded parser for query strings precisely because that is what real browsers and servers do, while RFC 3986 remains the grammar of record for URI structure. The split is therefore not a bug awaiting a fix but a permanent feature of the landscape, and the only viable strategy is to know which convention applies at every boundary you own.
Where the mismatch bites
Phone numbers with a plus prefix
E.164, the international telephone numbering standard, writes numbers with a leading plus: +15551234567. That plus is part of the number's canonical form, which makes phone numbers the single most common casualty of the convention split. A client that inserts the number into a URL without escaping sends a bare +; a form-style decoder on the server turns it into a space; and the application downstream sees a number with a whitespace prefix. Validation rejects it, or worse, a lenient parser strips the whitespace and stores a number missing its country code — which can then route to a completely different subscriber.
// The value: "+15551234567"
// Broken: raw insertion, no encoding
"/lookup?phone=" + phone;
// "/lookup?phone=+15551234567"
// Form-style decoding yields " 15551234567" — space where the plus was
// Safe: the plus is percent-encoded
"/lookup?phone=" + encodeURIComponent(phone);
// "/lookup?phone=%2B15551234567"
// Decodes as "+15551234567" under both conventions
Base64 values that were not made URL-safe
Standard base64 uses + and / in its alphabet, which makes raw base64 a poor citizen of a query string: every + is one form-decode away from becoming a space, and the decoded value no longer parses as base64 at all. This is precisely why base64url exists — it swaps + for - and / for _, characters that carry no special meaning in any URL context. JWTs use base64url for exactly this reason. If you must transmit standard base64 through a query parameter, percent-encode it fully and confirm the server decodes percent-escapes before it attempts base64 decoding; if you control the format, switch to base64url and sidestep the problem entirely.
Email addresses with plus-addressing
Several major mail providers support plus-addressing: a mailbox [email protected] also receives mail addressed to [email protected], which is a convenient way to trace where an address leaked. That convenience makes plus-tagged addresses popular in signup links — [email protected] — and it makes them a reliable source of this bug. Unencoded, the plus is form-decoded into a space, and the stored address is no longer deliverable in that form: validation may reject it, or a confirmation mail may go to a mangled local part. The failure is easy to misdiagnose as a mail-provider issue, because the mangled address still looks plausible after trimming. The rule is the same as for phone numbers: the plus here is data, so it must travel as %2B — encode the email like any other opaque value and verify the round trip before building signup flows on it.
Signatures computed over a value that changed
The nastiest variant involves signed values. Suppose an API tacks an HMAC onto a URL: ?data=report+2026&sig=..., where the signature was computed over report 2026 — the space having been written as + at signing time. If the receiving side decodes data as a literal plus instead of a space, the bytes no longer match, verification fails, and the request is rejected — with no indication that the entire problem is one character's decoding convention. Worse still is the silent version: a system that normalizes whitespace before verifying, passing the check while storing data that differs from what was signed. Whenever a value is signed, the exact decoded bytes must be pinned down on both sides, and the safest way to pin them is to make the encoding explicit — percent-encode everything, so no bare plus ever reaches the wire.
Who should encode what
The conventions only collide when producers and consumers disagree, so it helps to be precise about each side's job.
Producers building URLs programmatically should escape every literal plus as %2B and every space as %20. In JavaScript, encodeURIComponent does both — it never leaves a raw + in its output. URLSearchParams is the notable exception: it follows the form-urlencoded convention and serializes spaces as +, which is fine for servers that form-decode query strings — nearly all of them — but worth knowing when you compare outputs:
encodeURIComponent("blue shoes & C++");
// "blue%20shoes%20%26%20C%2B%2B"
new URLSearchParams({ q: "blue shoes & C++" }).toString();
// "q=blue+shoes+%26+C%2B%2B"
Both serializations are correct, and both decode to the same value under a form-style parser — the second merely relies on +-means-space, while the first avoids relying on any convention at all. For the deeper differences between the two encoding approaches, including where each one belongs, see encodeURI or encodeURIComponent.
Consumers parsing query strings should always decode percent-escapes, and should translate + to a space only when the string is known to come from a form-style producer. A backend endpoint that accepts HTML form submissions must form-decode; a generic URL-manipulation library should not, because it may be handed URLs produced under either convention. When a value travels through another layer of encoding on its way into a query parameter — the classic case being a full URL stuffed into a redirect parameter — every layer's convention must be accounted for separately; the walkthrough in double URL encoding covers how those layers stack.
The failure is never that + means space. The failure is that one side assumed the other knew. Every plus-related bug reduces to a producer and a consumer disagreeing about which convention applies to one bare character.
A debugging workflow for plus-sign bugs
When a query parameter arrives looking wrong, resist the urge to patch the value in place. Work the problem in order:
1. Capture the raw query string. Look at the exact bytes on the wire — the network tab in devtools, the server access log, or a temporary echo endpoint. Do not inspect the value through your framework's request object at this stage; by the time you see it there, a decoder has already run and the evidence is gone. You want the string as the client sent it, before anyone interpreted anything.
2. Decode percent-escapes first, and only percent-escapes. Replace every %XX with the byte it names: %2B becomes +, %20 becomes a space. This step is unconditional — both conventions agree on it. After this pass, any remaining + in the string is either meaningful data or a form-encoded space, and nothing else.
3. Decide what the remaining pluses mean, based on the encoding context. Ask one question: who produced this string? If it came from an HTML form, from URLSearchParams, or from a client library documented to form-encode, treat + as a space. If it came from hand-built URLs, from an API client using encodeURIComponent, or from anything speaking generic RFC 3986, treat + as data. If you cannot determine the producer, the presence of %20 elsewhere in the same string is a useful clue: a form-style serializer would have emitted + instead, so %20 suggests a generic encoder wrote the string — and its pluses are probably literal.
4. Compare against what the producer intended. Reconstruct the expected value and diff. A mismatch at this point is no longer an encoding mystery; it is a documented convention disagreement between two specific pieces of code, and the fix is to make one of them explicit — usually by percent-encoding the plus on the producing side.
As a worked trace, suppose the raw capture shows phone=%2B15551234567&ref=a+b. Step 2 percent-decodes unconditionally: the phone parameter becomes +15551234567 and the ref parameter becomes a+b. Step 3 then asks about the producer. If this request was generated by a form or a form-style serializer, ref contains a b; if it was generated with encodeURIComponent-style encoding, ref contains the literal a+b. The phone value needs no decision at all — its encoding protected it. Notice that two parameters in one query string can follow different conventions only if different code produced them; in practice, mixed conventions in a single capture almost always mean one layer encoded values individually while another assembled the string, and finding that boundary is the real fix.
A minimal decoder that makes the decision explicit, rather than hiding it inside a framework, looks like this:
function decodeQueryValue(raw, { formEncoded = false } = {}) {
// Step 2: percent-escapes first, unconditionally
let value = raw.replace(/%([0-9A-Fa-f]{2})/g, (_, h) =>
String.fromCharCode(parseInt(h, 16))
);
// Step 3: the plus decision, driven by context
if (formEncoded) {
value = value.replace(/\+/g, " ");
}
return value;
}
decodeQueryValue("a+b"); // "a+b" — generic
decodeQueryValue("a+b", { formEncoded: true }); // "a b" — form-style
decodeQueryValue("a%2Bb"); // "a+b" — same either way
(Production code should decode to UTF-8 bytes rather than single code units — the snippet is simplified to show the ordering. The point it illustrates does not change: percent-decoding is unconditional; plus-translation is a choice.)
One further trap to watch for when the parameter in question is itself a URL — a returnTo, next, or redirect value: the inner URL's query string gets decoded along with everything else, and a plus inside the inner parameters is now two layers deep in convention decisions. That scenario has its own failure catalogue in redirect URLs in query parameters.
The recommendation, stated plainly
Everything above compresses into four defaults that are easy to apply and easy to defend in code review.
Use %20 for spaces in URLs you build. It decodes correctly under every convention and every framework. A bare + for space is only safe when you know the receiving parser form-decodes — true for most, but why depend on it? %20 costs four characters and removes an assumption. A URLSearchParams round-trip is the exception that proves the rule: emit and parse on the same side of the convention, and the pair stays consistent.
Treat + as data unless the string came from an HTML form. Generic decoders, URL-manipulation utilities, and anything processing third-party URLs should leave pluses alone. Only a consumer that knows its input is form-encoded — an endpoint behind a form submission, a parser paired with a known form-style serializer — should translate plus to space.
Never transmit a literal plus as a bare +. Whatever the receiving convention, %2B decodes to a plus everywhere. A bare plus is the only encoding decision in a query string whose meaning is genuinely ambiguous, so it is the one decision never to leave implicit.
Never blanket-replace pluses in stored URLs. When cleaning up legacy data, the temptation is a find-and-replace of + with %2B across stored query strings. That corrupts every URL where the plus really did mean a space under form conventions. Each stored URL's pluses mean whatever its producer meant — decide per source, not per character.
When you find a plus bug in production, fix the encoding at the boundary, not the decoding after the fact. Adding a replace(" ", "+") on the receiving side papers over one symptom while every other consumer of that value inherits the ambiguity.
Framework defaults differ, so test yours and write it down
There is no single spec that settles the question for all runtimes, so each language and server made its own call — and they did not all call the same way. In JavaScript, URLSearchParams both emits and consumes +-as-space. In Python, urllib.parse.unquote leaves pluses alone while unquote_plus converts them, and quote emits %20 while quote_plus emits + — the two conventions sit side by side in one module. In PHP, $_GET form-decodes, urlencode() emits pluses for spaces, and rawurlencode() emits %20. Java's URLEncoder.encode is named for URLs but implements the form-urlencoded convention, emitting + for spaces — a naming trap that has misled generations of developers. Most web frameworks, following the form tradition, form-decode query strings by default, including ones written in languages whose standard libraries also offer a generic decoder.
The practical consequence: two services in the same stack can disagree about a bare plus, and both are behaving exactly as their authors intended. So instead of assuming, run a three-value probe against any component that decodes query strings — send x=a+b, x=a%2Bb, and x=a%20b, observe what arrives, and record the results where your team keeps its integration notes. Three requests and a written sentence buy permanent immunity to this entire bug class.
Test it yourself
Open the URL Workbench, paste in a query string containing a+b, a%2Bb, and a%20b, and decode it both ways. Watching one character resolve to a space or stay a plus depending solely on the selected convention makes the split concrete in a way no table can — and once you have seen it, you will never again ship a bare plus without asking which decoder is waiting on the other end.
Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.