encodeURI vs encodeURIComponent Explained
The URL specification (RFC 3986) mandates that only certain ASCII characters are valid. Non-ASCII characters (like Chinese or accents) and reserved delimiters must be converted to hexadecimal percent-encoding:
- encodeURIComponent (component encoding):Encodes almost all special characters including
/,?,&,=, and#. Essential when passing one URL as a query string parameter inside another URL. - encodeURI (whole-URL encoding):Encodes illegal characters such as spaces and non-Latin text while preserving structural URL characters like
http://, slashes, and question marks.
What happens in the page
rfc3986Encode() starts from encodeURIComponent and then escapes the five characters that function leaves alone — the exclamation mark, apostrophe, round brackets and asterisk — because RFC 3986 does not list them as unreserved. That difference matters when a signature is computed over the encoded string: a stray apostrophe changes the hash. transform() applies the chosen mode, which decides whether structural characters such as slash, colon, question mark and ampersand survive, so encoding a whole URL does not destroy the scheme and path.
Where it breaks down
The tool cannot infer which mode you meant; a value already encoded once will be encoded again, producing double escapes. Space is the other trap: %20 is correct in a path while + is the form convention, and guessing wrong silently changes the value. Text that was encoded with a legacy single-byte charset decodes to mojibake, because the page assumes UTF-8 throughout.
Privacy: no data leaves this tab
The string is transformed with built-in browser functions; the page makes no request and keeps no history, so a URL containing a token is not stored anywhere after you close the tab.
Frequently asked questions
Why does my encoded link 404?
Most likely the whole URL was encoded, so the scheme and slashes became percent sequences. Switch to the component mode, or encode only the value.
What is the difference between %20 and +?
+ means space only in form-encoded bodies; in a path it is a literal plus. Use %20 when in doubt.
Why do Chinese characters become three escapes?
UTF-8 encodes a CJK character in three bytes, and each byte becomes its own percent sequence. That is correct, not a bug.