The Double-Encoding Bug You Will Hit Eventually
By toolbelt maintainers ·
Updated
A space becomes %20, then %2520, and suddenly your search returns nothing. Here is why, and how to stop it.
What is this tool?
URL encoding replaces characters that are illegal or ambiguous in a URL with percent-escapes. Correct encoding is the difference between a working query and a mysterious empty result.
How it works
There are two functions and using the wrong one is the usual mistake. encodeURIComponent encodes everything meaningfully, including slashes and question marks, so it suits a single value. encodeURI leaves URL structure intact, so it suits a whole URL. I give you both.
Example
Value: a b&c encodeURIComponent → a%20b%26c encodeURI → a%20b&c Paste the second into a query parameter and the & splits your value in two.
When to use it
Building a URL with a search term, a file path, or any user input. Debugging why a link with a plus sign in it behaves oddly. Reading logs where everything is percent-escaped.
Optimization Tips
Encode once, at the point where you build the URL. If you encode in the form handler and again in the request builder, you get %2520. When you see a double-encoded value, remove the earlier encoding rather than adding a decode.
Frequently Asked Questions
When do I use which?
Why does + become a space sometimes?
What is %2F?
Does decoding ever fail?
Related tools
- Base64 Encoder/DecoderEncode and decode Base64 strings safely. Supports full UTF-8 characters, emojis, and binary data. Ideal for debugging data URLs or API authentication headers.
- JWT DecoderDecode JSON Web Tokens to inspect the header and payload. Debug authentication flows, check expiration times, and view user roles without verifying the signature.
- JWT SignerCreate a signed JSON Web Token with HMAC SHA-256, SHA-384 or SHA-512. Encode the header and payload and sign it from a secret, entirely in your browser.
- Env ValidatorCheck a .env file for duplicate keys, unclosed quotes, unquoted spaces and placeholder secrets before they break a deploy. Reports the line number of each problem.