首页 全栈极客与开发辅助内容详情

URL Encoder / Decoder: Percent-Encoding for Links and Parameters - Percent-encoding, honest about broken escapes

2026-11-17 3 访客
URL Encoder / Decoder: Percent-Encoding for Links and Parameters

站点名称:URL Encoder / Decoder: Percent-Encoding for Links and Parameters

所属分类:全栈极客与开发辅助

官方网址:https://www.9314.cn/tools/url-encoder/en/

SEO查询: 爱站网 站长工具

进入网站

站点介绍

URL Encoder / Decoder: Percent-Encoding for Links and Parameters

Last week I spent an evening debugging a share link for someone: a long URL with Chinese parameters went into a QR generator, and every scan came back 400. The culprit turned out to be unencoded spaces and CJK characters - the receiving end parsed raw bytes and the URL just broke. This page was built to that evening's spec: paste, convert, pick a mode, and get honest errors when something is off.

The short version

  • Two modes: encodeURIComponent (full - & = ? # also become %XX, for parameter values) and encodeURI (structure-preserving, for whole URLs), one-click switch with automatic direction detection.
  • Line-by-line batches: multi-line input processes each line independently - paste a whole list of parameters in one go.
  • Broken escapes get called out: %ZZ or %G1 triggers an error with the exact line and position, because a broken escape usually means the link was truncated somewhere upstream - silently mangling it just moves the bug somewhere harder to find.
  • Browser-local computation, zero uploads; RFC 3986 semantics (+ is never a space); 1MB cap keeps it responsive.

Why CJK characters become %E4%BD%A0

URL encoding first splits the string into UTF-8 bytes; a CJK character is usually 3 bytes, and each byte becomes %XX. The UTF-8 bytes of one common character are E4 BD A0, hence %E4%BD%A0 - nine characters representing one glyph, which is normal. Most emoji are 4 bytes, producing 12 characters.

Once that clicks, the "shorter is better" obsession can rest: length is dictated by the encoding rules, not by the tool being lazy.

How to pick between the two modes

One sentence to remember: encode values with full mode, encode whole URLs with structure-preserving mode. Search terms, notes, usernames - anything going into a query string - belong to encodeURIComponent, which also converts & = ? # so special characters inside a value cannot break the URL structure. A fully assembled link that just needs its CJK characters converted belongs to encodeURI, which keeps the structure characters intact. When in doubt, try both and paste the result into an address bar.

FAQ

encodeURIComponent or encodeURI - which one do I need?

Rule of thumb: encode a parameter value with encodeURIComponent, encode a whole URL with encodeURI. encodeURIComponent also converts &, =, ? and # into %XX so special characters inside a value cannot break the URL structure; encodeURI leaves those intact and only converts characters that are outright illegal in a URL, like spaces and non-ASCII text. When in doubt, try both - paste each result into a browser address bar and see which one survives.

Why does decoding fail with an illegal % sequence?

Your input contains something like %ZZ or %G1 - characters after the percent sign that are not valid hexadecimal - or a % with fewer than two characters following it. Plenty of online tools quietly skip or pass those through; this page raises an error and points at the first offending position instead, because a broken escape usually means the link you copied was truncated or mangled somewhere. Fix the % (escape it as %25) or remove the damaged fragment, then retry.

Why does one CJK character become nine characters like %E4%BD%A0?

URL encoding first splits the string into UTF-8 bytes. A CJK character is usually 3 bytes, and each byte becomes one %XX triplet - so 3 bytes times 3 characters each equals 9. Emoji run longer: most are 4 bytes, producing 12 characters. That is not a bug; it is exactly what RFC 3986 prescribes.

Why did my + signs turn into spaces after decoding elsewhere?

They did not change here. That behavior comes from the legacy application/x-www-form-urlencoded format, which encodes spaces as + and decodes + back to spaces. Pure URL percent-encoding (RFC 3986) writes spaces as %20 and treats + as a literal plus. This tool follows RFC 3986 and keeps + as-is; if your data came from an old form submission, replace + with %20 before decoding here.

Is my text uploaded anywhere?

No. Encoding and decoding happen entirely inside this device's browser - there is no upload endpoint and it works offline. Only your mode preference lives in this browser's localStorage; it does not follow you to another device, and "Clear my data" in the footer removes it.

中文版:https://www.9314.cn/tools/url-encoder/

 暂无评论,快来抢沙发吧~

发布评论