ForLookup converts the domain into a canonical form suitable for table lookups and other comparisons. TL;DR Use this instead of strings.ToLower to prepare domain for lookups. Domains that contain invalid UTF-8 or invalid A-label domains are simply converted to local-case using strings.ToLower, but
(domain string)
| 39 | // domains are simply converted to local-case using strings.ToLower, but the |
| 40 | // error is also returned. |
| 41 | func ForLookup(domain string) (string, error) { |
| 42 | uDomain, err := idna.ToUnicode(domain) |
| 43 | if err != nil { |
| 44 | return strings.ToLower(domain), err |
| 45 | } |
| 46 | |
| 47 | // Side note: strings.ToLower does not support full case-folding, so it is |
| 48 | // important to apply NFC normalization first. |
| 49 | uDomain = norm.NFC.String(uDomain) |
| 50 | uDomain = strings.ToLower(uDomain) |
| 51 | uDomain = strings.TrimSuffix(uDomain, ".") |
| 52 | return uDomain, nil |
| 53 | } |
| 54 | |
| 55 | // Equal reports whether domain1 and domain2 are equivalent as defined by |
| 56 | // IDNA2008 (RFC 5890). |
no test coverage detected