Skip to content

Commit 1d7c5b9

Browse files
authored
Merge pull request #20 from nyaruka/shorter-tels
allow single digit shortcodes for tel URNs
2 parents 5682129 + 2ae02cf commit 1d7c5b9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

urns/urns.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func IsValidScheme(scheme string) bool {
7878
}
7979

8080
var nonTelCharsRegex = regexp.MustCompile(`[^0-9a-z]`)
81-
var telRegex = regexp.MustCompile(`^\+?[a-zA-Z0-9]{3,64}$`)
81+
var telRegex = regexp.MustCompile(`^\+?[a-zA-Z0-9]{1,64}$`)
8282
var twitterHandleRegex = regexp.MustCompile(`^[a-zA-Z0-9_]{1,15}$`)
8383
var emailRegex = regexp.MustCompile(`^[^\s@]+@[^\s@]+$`)
8484
var viberRegex = regexp.MustCompile(`^[a-zA-Z0-9_=/+]{1,24}$`)

urns/urns_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ func TestValidate(t *testing.T) {
206206
{"tel:+250788383383", ""},
207207
{"tel:+250123", ""},
208208
{"tel:1337", ""},
209+
{"tel:1", ""}, // one digit shortcodes are a thing
209210
{"tel:PRIZES", ""},
210211
{"tel:cellbroadcastchannel50", ""},
211212

212213
// invalid tel numbers
213214
{"tel:07883 83383", "invalid tel number"}, // can't have spaces
214-
{"tel:12", "invalid tel number"}, // too short
215+
{"tel:", "cannot be empty"}, // need a path
215216

216217
// twitter handles
217218
{"twitter:jimmyjo", ""},
@@ -301,7 +302,7 @@ func TestTelURNs(t *testing.T) {
301302
{"0788383383", "ZZ", "tel:0788383383", false},
302303
{"PRIZES", "RW", "tel:prizes", false},
303304
{"PRIZES!", "RW", "tel:prizes", false},
304-
{"1", "RW", "", true},
305+
{"1", "RW", "tel:1", false},
305306
{"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "RW", "", true},
306307
}
307308

0 commit comments

Comments
 (0)