diff --git a/utils/phone.go b/utils/phone.go index 8cb22fe7c..953348701 100644 --- a/utils/phone.go +++ b/utils/phone.go @@ -24,7 +24,15 @@ func ParsePhoneNumber(s string, country i18n.Country) string { return "" } - return formatted + // TODO there is a problem in urns package where a number +810000000977123456 is considered valid because it allows + // unlimited zeros between the country code and the number... but our validation for phone URNs thinks it's too + // long, so we validate explicitly here + urn, err := urns.New(urns.Phone, formatted) + if err != nil { + return "" + } + + return urn.Path() } // FindPhoneNumbers finds phone numbers anywhere in the given string diff --git a/utils/phone_test.go b/utils/phone_test.go index bcf7f8548..95e05cb39 100644 --- a/utils/phone_test.go +++ b/utils/phone_test.go @@ -15,6 +15,7 @@ func TestParsePhoneNumber(t *testing.T) { assert.Equal(t, "", utils.ParsePhoneNumber("tel = +250788383383", "RW")) assert.Equal(t, "", utils.ParsePhoneNumber("Hi my number is +250788383383 thanks", "RW")) assert.Equal(t, "", utils.ParsePhoneNumber("Hi my phone is (202) 456-1111 thanks", "US")) + assert.Equal(t, "", utils.ParsePhoneNumber("+810000000977123456", "CD")) assert.Equal(t, "+250788383383", utils.ParsePhoneNumber("+250788383383", "")) assert.Equal(t, "+250788383383", utils.ParsePhoneNumber("0788 383 383", "RW"))