Hongmu Notes

🧷 URL encoding and decoding

The encoding gives two writing methods at the same time, and the decoding restores the %XX content.

Instructions for use

  • Click "Encode" to get both encodeURI and encodeURIComponent results at the same time
  • Click "Decode" to restore %XX content using decodeURIComponent
  • "Content exchange" backfills the results into the input box, and a prompt will be given for illegal percent signs.

Parameter value encoding

If the parameter value contains & or =, direct splicing will be parsed into additional parameter items and must be encoded first.

📌 Which encoding should be used for parameter values?

Use encodeURIComponent: it will also encode & and =, so parameter values will not be misinterpreted as new parameters; use encodeURI for the entire link, and the division of labor between the two is different.

📌 Coding rules

The encoding button is executed twice at the same time: once using encodeURI, retaining structural symbols such as colons, slashes, question marks, pound signs, square brackets, @ and &, etc., and only encoding characters such as spaces and Chinese; another time using encodeURIComponent, encoding structural symbols as well, so the result is more suitable as a parameter value. The decode button only calls decodeURIComponent. If it encounters an incomplete sequence of percent signs, a prompt will be given and the result will be cleared.

🧭 Common uses

It is common to assemble query links with Chinese characters or spaces, safely put user input into parameter values, check the encoded string returned by the backend, and troubleshoot problems such as "& in parameters are treated as delimiters." The two encoding results are given side by side, and the impact of structural symbols can be intuitively seen.

All keywords and tutorials 12

❓ FAQ

Can the entire query string be encoded?
Yes, but it is more secure to encode each parameter value separately to facilitate troubleshooting.
Can I spell it directly after encoding?
Yes, just spell the encoded value after ?key=.
Checkpointing parameter value encoding
Symbols such as & and = that interfere with parsing no longer appear in parameter values.