idn-0.1.2.0: Pure Haskell IDN and Punycode implementation
Safe HaskellNone
LanguageHaskell2010

Data.Text.IDN

Description

High-level API for Internationalized Domain Names (IDN) processing.

This module provides functions for converting between Unicode and ASCII domain names, following the IDNA2008 specification (RFC 5890-5893).

Overview

Internationalized Domain Names allow domain names to contain non-ASCII characters. This library implements IDNA2008, which uses Punycode encoding to represent Unicode characters in ASCII-compatible form.

Example

>>> toASCII "münchen.de"
Right "xn--mnchen-3ya.de"
>>> toUnicode "xn--mnchen-3ya.de"
Right "münchen.de"
>>> validateLabel "example"
Right ()

See Also

  • Punycode for low-level Punycode encoding/decoding
  • RFC 5890-5893 for the full IDNA2008 specification
Synopsis

Main API

toASCII :: Text -> Either IDNError Text Source #

Convert a Unicode domain name to ASCII (A-label) form per RFC 5891.

Converts each label in the domain name to its ASCII-compatible form. Unicode labels are encoded using Punycode and prefixed with "xn--". ASCII labels are normalized to lowercase (case-insensitive per DNS).

Examples

>>> toASCII "münchen.de"
Right "xn--mnchen-3ya.de"
>>> toASCII "EXAMPLE.COM"
Right "example.com"

Errors

Returns Left with IDNError if: * Any label is empty or too long * Any label contains disallowed code points * Bidirectional text rules are violated * Contextual validation fails

Since: 0.1.0.0

toUnicode :: Text -> Either IDNError Text Source #

Convert an ASCII domain name to Unicode (U-label) form per RFC 5891.

Converts each label in the domain name to its Unicode form. Punycode-encoded labels (starting with "xn--") are decoded to Unicode. Pure ASCII labels are validated and passed through unchanged.

Examples

>>> toUnicode "xn--mnchen-3ya.de"
Right "münchen.de"
>>> toUnicode "example.com"
Right "example.com"

Errors

Returns Left with IDNError if: * Any label is empty or too long * Punycode decoding fails * Any label contains disallowed code points * Bidirectional text rules are violated

Since: 0.1.0.0

validateLabel :: Text -> Either IDNError () Source #

Validate a single domain label per IDNA2008 rules.

Performs comprehensive validation including: * Length constraints (max 63 characters) * Hyphen position rules * Code point validity (PVALID, CONTEXTJ, CONTEXTO) * Contextual rule validation * Bidirectional text rules (RFC 5893)

Examples

>>> validateLabel "example"
Right ()
>>> validateLabel ""
Left EmptyLabel

Errors

Returns Left with IDNError if validation fails. See IDNError constructors for specific error types.

Since: 0.1.0.0

Types