How it works
Encoding escapes every character that is not an unreserved URL character. A space becomes %20, a slash becomes %2F, and a question mark becomes %3F. That is what you want inside a query parameter. It is more aggressive than encodeURI, which would leave the slash alone.
Decoding turns %20 back into a space. A stray % that is not followed by two hex digits is an error, and the page says so instead of returning a broken string. Nothing is uploaded.
Formula
- Space
a b → a%20b - Slash
a/c → a%2Fc
Worked examples
A query value
“a b/c?x=1” encodes to a%20b%2Fc%3Fx%3D1. Drop that into a single parameter without the parameter breaking on the slash or the question mark.
A bad percent
A lone % does not decode. The page reports that the encoding is not valid.
| Character | Encoded | Why |
|---|---|---|
| Space | %20 | Otherwise it splits the query |
| / | %2F | Otherwise it looks like a path |
| ? | %3F | Otherwise it starts a new query |
| = | %3D | Otherwise it looks like another parameter |
Common questions
Is the text uploaded?
No. Encoding runs in your browser.
Why not encodeURI?
encodeURI is for a whole URL and leaves / ? & = alone. encodeURIComponent is for one value. This page uses the component form.
Does + mean a space?
Not here. A space encodes as %20. Some form bodies use +. This decoder does not treat + as a space.
What about Unicode?
Characters outside ASCII are UTF-8 percent-encoded, so é survives a round trip.