mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-19 14:57:04 +00:00
Normalize domains
We should ignore the domains' case, and treat them uniformly, specially when it comes to local domains. This patch extends the existing normalization (IDNA, keeping domains as UTF8 internally) to include case conversion and NFC form for consistency.
This commit is contained in:
@@ -33,10 +33,42 @@ func TestUser(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDomain(t *testing.T) {
|
||||
valid := []struct{ user, norm string }{
|
||||
{"ÑAndÚ", "ñandú"},
|
||||
{"Pingüino", "pingüino"},
|
||||
{"xn--aca-6ma", "ñaca"},
|
||||
{"xn--lca", "ñ"}, // Punycode is for 'Ñ'.
|
||||
{"e\u0301", "é"}, // Transform to NFC form.
|
||||
}
|
||||
for _, c := range valid {
|
||||
nu, err := Domain(c.user)
|
||||
if nu != c.norm {
|
||||
t.Errorf("%q normalized to %q, expected %q", c.user, nu, c.norm)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("%q error: %v", c.user, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
invalid := []string{"xn---", "xn--xyz-ñ"}
|
||||
for _, u := range invalid {
|
||||
nu, err := Domain(u)
|
||||
if err == nil {
|
||||
t.Errorf("expected Domain(%+q) to fail, but did not", u)
|
||||
}
|
||||
if nu != u {
|
||||
t.Errorf("%+q failed norm, but returned %+q", u, nu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddr(t *testing.T) {
|
||||
valid := []struct{ user, norm string }{
|
||||
{"ÑAndÚ@pampa", "ñandú@pampa"},
|
||||
{"Pingüino@patagonia", "pingüino@patagonia"},
|
||||
{"pe\u0301@le\u0301a", "pé@léa"}, // Transform to NFC form.
|
||||
}
|
||||
for _, c := range valid {
|
||||
nu, err := Addr(c.user)
|
||||
|
||||
Reference in New Issue
Block a user