Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for numbers that pass urns.ParseNumber but fail phone URN valdiation #1284

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion utils/phone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions utils/phone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Loading