Skip to content

Commit

Permalink
Bring back auto adding of + to sufficiently long phone numbers when p…
Browse files Browse the repository at this point in the history
…arsing URNs
  • Loading branch information
rowanseymour committed May 7, 2024
1 parent cb0fea5 commit 3b68358
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions urns/phone.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func ParsePhone(raw string, country i18n.Country) (URN, error) {
raw = "+" + raw
}

// if we're sufficienly long and don't start with a 0 then add a +
if len(raw) >= 11 && !strings.HasPrefix(raw, "0") {
raw = "+" + raw
}

number, err := parsePhoneOrShortcode(raw, country)
if err != nil {
if err == phonenumbers.ErrInvalidCountryCode {
Expand Down
1 change: 1 addition & 0 deletions urns/phone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestParsePhone(t *testing.T) {
{"0877747666", "ID", "tel:+62877747666"},
{"07531669965", "GB", "tel:+447531669965"},
{"263780821000", "ZW", "tel:+263780821000"},
{"254791541111", "US", "tel:+254791541111"}, // international but missing + and wrong country

{"1", "RW", "tel:1"},
{"123456", "RW", "tel:123456"},
Expand Down

0 comments on commit 3b68358

Please sign in to comment.