unicode-idna

    UTS #46 IDNA processing for MoonBit

    unicode
    idna
    uts46
    domain
    Download zip
    Version
    0.8.0
    License
    Apache-2.0
    Last updated
    5 days ago
    Downloads
    18K

    #unicode-idna

    Unicode IDNA processing for MoonBit following UTS #46 and Unicode 18.0.0.

    moon add moonbit-community/unicode-idna

    to_ascii and to_unicode use UTS #46 mapping, NFC normalization, and label validation. Both accept optional IDNA2008 checks:

    • check_idna2008=true restricts the resulting Unicode labels to the IDNA2008 PVALID, CONTEXTJ, and CONTEXTO categories. Other code points raise DisallowedCodePoint(cp~). This only checks the repertoire; check_joiners remains responsible for validating CONTEXTJ characters in context.
    • check_contexto=true independently validates the RFC 5892 ContextO rules. Violations raise InvalidContextO(cp~).

    Both new options default to false. They also check Unicode labels decoded from Punycode. Enable both alongside the default checks to combine IDNA2008 repertoire and contextual validation with the existing label checks.

    let ascii = try! @idna.to_ascii(
    "ÖBB.at",
    check_idna2008=true,
    check_contexto=true,
    )
    // "xn--bb-eka.at"

    The input still undergoes UTS #46 mapping: the example accepts and lowercases ÖBB.at. These options do not provide strict validation of unmodified IDNA2008 input. Symbols such as ☕ are rejected by check_idna2008 even though UTS #46 allows them.

    See the repository root README for the remaining options and examples.

    IdnaError

    pub(all) suberror IdnaError {
    PunycodeError(
    PunycodeError
    )
    DisallowedCodePoint(cp~ : Int)
    InvalidLabel(String)
    InvalidHyphen
    LabelTooLong
    DomainTooLong
    EmptyLabel
    InvalidBidi
    InvalidJoiner
    InvalidContextO(cp~ : Int)
    InvalidAcePrefix
    LeadingCombiningMark
    }

    Error types for IDNA processing
    impl Show for IdnaError

    IdnaError::output

    fn IdnaError::output(self : IdnaError, logger : &Logger) -> Unit

    IdnaError::to_string

    fn IdnaError::to_string(self : IdnaError) -> String

    to_ascii

    fn to_ascii(domain : String, use_std3_ascii_rules? : Bool, check_hyphens? : Bool, check_bidi? : Bool, check_joiners? : Bool, check_idna2008? : Bool, check_contexto? : Bool, verify_dns_length? : Bool) -> String raise IdnaError

    Convert a domain name to ASCII (for DNS lookup) This is the main entry point for IDNA ToASCII operation

    check_idna2008 additionally rejects Unicode label characters classified as DISALLOWED or UNASSIGNED by IDNA2008. check_contexto checks the RFC 5892 CONTEXTO rules. Both default to false and preserve UTS #46 mapping and normalization; ContextJ remains controlled by check_joiners.

    to_unicode

    fn to_unicode(domain : String, use_std3_ascii_rules? : Bool, check_hyphens? : Bool, check_bidi? : Bool, check_joiners? : Bool, check_idna2008? : Bool, check_contexto? : Bool) -> String raise IdnaError

    Convert a domain name to Unicode (for display) This is the main entry point for IDNA ToUnicode operation

    check_idna2008 additionally rejects Unicode label characters classified as DISALLOWED or UNASSIGNED by IDNA2008. check_contexto checks the RFC 5892 CONTEXTO rules. Both apply to decoded A-labels as well as Unicode input, default to false, and preserve UTS #46 mapping and normalization.