fix: canonicalize phone numbers as E.164

This commit is contained in:
richjohnrambo
2026-08-18 01:23:18 +08:00
parent bf562c7d56
commit e063e7879e
7 changed files with 103 additions and 6 deletions
+25
View File
@@ -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")
}
}