Unicode.IDNA.Bidi (Unicode IDNA v0.1.0)

View Source

RFC 5893 Right-to-Left Scripts for Internationalized Domain Names — the IDNA 2008 bidi rule.

A label is Bidi if it contains any character whose Bidi_Class is R, AL or AN. The bidi rule applies only to bidi labels; pure-LTR labels are unaffected.

Summary

Functions

Returns true if the label contains a right-to-left character and therefore must satisfy the bidi rule.

Validates a label against the RFC 5893 bidi rule.

Validates a label as part of a bidi domain.

Functions

bidi_label?(label)

@spec bidi_label?(String.t()) :: boolean()

Returns true if the label contains a right-to-left character and therefore must satisfy the bidi rule.

Examples

iex> Unicode.IDNA.Bidi.bidi_label?("hello")
false

iex> Unicode.IDNA.Bidi.bidi_label?("שלום")
true

validate(label)

@spec validate(String.t()) :: :ok | {:error, :bidi}

Validates a label against the RFC 5893 bidi rule.

Arguments

  • label is a String.t/0 representing one already-mapped domain label.

Returns

  • :ok if the label satisfies the bidi rule (or is not a bidi label).

  • {:error, :bidi} otherwise.

Examples

iex> Unicode.IDNA.Bidi.validate("hello")
:ok

iex> Unicode.IDNA.Bidi.validate("שלום")
:ok

validate_in_bidi_domain(label)

@spec validate_in_bidi_domain(String.t()) :: :ok | {:error, :bidi}

Validates a label as part of a bidi domain.

RFC 5893 §1.4 requires that, in a domain name containing at least one right-to-left label, every label — including LTR labels — satisfies the bidi rule. Use this function to enforce that whole-domain rule label-by-label; use validate/1 for isolated labels that are not known to be part of a bidi domain.

Examples

iex> Unicode.IDNA.Bidi.validate_in_bidi_domain("hello")
:ok

iex> Unicode.IDNA.Bidi.validate_in_bidi_domain("0a")
{:error, :bidi}