fix: canonicalize phone numbers as E.164
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
//go:build mysql
|
||||
// +build mysql
|
||||
|
||||
package mysql
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeUserPhone(t *testing.T) {
|
||||
for input, want := range map[string]string{
|
||||
"13800138000": "+8613800138000",
|
||||
"+8613800138000": "+8613800138000",
|
||||
"tel:+17025550001": "+17025550001",
|
||||
} {
|
||||
got, err := normalizeUserPhone(input)
|
||||
if err != nil {
|
||||
t.Fatalf("normalize %q: %v", input, err)
|
||||
}
|
||||
if got != want {
|
||||
t.Fatalf("normalize %q: got %q, want %q", input, got, want)
|
||||
}
|
||||
}
|
||||
if _, err := normalizeUserPhone("12345"); err == nil {
|
||||
t.Fatal("invalid phone unexpectedly accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user