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
+1 -1
View File
@@ -129,7 +129,7 @@ func (*validator) PreCheck(cred string, params map[string]any) (string, error) {
}
countryCode, ok := params["countryCode"].(string)
if !ok {
countryCode = "US"
countryCode = "CN"
}
number, err := phonenumbers.Parse(cred, countryCode)
if err != nil {
+13
View File
@@ -0,0 +1,13 @@
package tel
import "testing"
func TestPreCheckDefaultsToChina(t *testing.T) {
got, err := (&validator{}).PreCheck("13800138000", map[string]any{})
if err != nil {
t.Fatal(err)
}
if got != "tel:+8613800138000" {
t.Fatalf("got %q, want tel:+8613800138000", got)
}
}