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

InputhostnamepathnameObserved distinction
https://例え.テスト/pathxn--r8jz45g.xn--zckzah/pathUnicode host → Punycode
https://münich.example/caféPunycode host/caf%C3%A9Host and path use different serialization
https://example.com/%E8%B7%AFexample.com/%E8%B7%AFEscape remains path data
https://xn--r8jz45g.xn--zckzah/pathSame Punycode host/pathAlready 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.