fix: canonicalize phone numbers as E.164
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user