Exonerate.Formats.Punycode (exonerate v1.2.2)

Copy Markdown View Source

Minimal Punycode implementation for IDN hostname validation. Based on RFC 3492: https://www.rfc-editor.org/rfc/rfc3492

This implementation provides encode/decode functions sufficient for validating internationalized domain names without requiring the full :idna library.

Summary

Functions

Decode a punycode string to a unicode charlist.

Encode a unicode charlist to punycode.

Functions

decode(input)

@spec decode(charlist()) :: charlist()

Decode a punycode string to a unicode charlist.

Raises ArgumentError if the punycode is invalid or decodes to characters that are not valid for domain names (control characters, code points above Unicode range, etc.).

Examples

iex> Exonerate.Formats.Punycode.decode(~c"bcher-kva")
~c"bücher"

iex> Exonerate.Formats.Punycode.decode(~c"Mnchen-3ya")
~c"München"

encode(input)

@spec encode(charlist()) :: charlist()

Encode a unicode charlist to punycode.

Examples

iex> Exonerate.Formats.Punycode.encode(~c"bücher")
~c"bcher-kva"

iex> Exonerate.Formats.Punycode.encode(~c"München")
~c"Mnchen-3ya"