URL encoding boundary · Updated November 4, 2026
URL Encode IDN Hostnames: Punycode Is Not Percent-Encoding
A Unicode hostname and a percent-encoded path are different URL parts. In the tested parser, https://例え.テスト/path becomes a Punycode hostname, while https://example.com/%E8%B7%AF keeps the escape in the pathname. Do not percent-encode a hostname as if it were path text.
The boundary in four real fixtures
| Input | hostname | pathname | Observed distinction |
|---|---|---|---|
https://例え.テスト/path | xn--r8jz45g.xn--zckzah | /path | Unicode host → Punycode |
https://münich.example/café | Punycode host | /caf%C3%A9 | Host and path use different serialization |
https://example.com/%E8%B7%AF | example.com | /%E8%B7%AF | Escape remains path data |
https://xn--r8jz45g.xn--zckzah/path | Same Punycode host | /path | Already serialized hostname |
Why a generic encoder is the wrong test
encodeURIComponent() produces text escapes; it does not implement IDNA hostname serialization. Test the complete URL with the parser your client uses, then record hostname and pathname separately. A path fixture cannot prove a hostname result.
Rerun the evidence
Download the Node regression script, four fixtures and recorded results. Run node downloads/idn-hostname-regression.cjs. The run used Node v24.19.0 and asserts the hostname/path boundary.
For component escaping, return to the URL encoder. This page tests host serialization, not a new general encoder.