Skip to content

Commit 369b7e6

Browse files
authored
Merge pull request #11 from eritikass/improved-username-regex
improve username validation regex to match long usernames with "-" them
2 parents 0350bb4 + ca7dc5e commit 369b7e6

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

slack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func Slack(markdown string, options ...SlackConvertOptions) string {
5353
linkRegex := ".*"
5454

5555
// usernames @xxx
56-
re = regexp.MustCompile(startOfPattern + "@(?P<USERNAME>[a-zA-Z0-9]{3,20})" + endOfPattern)
56+
re = regexp.MustCompile(startOfPattern + "@(?P<USERNAME>[a-z-A-Z0-9]{3,20})" + endOfPattern)
5757
markdown = re.ReplaceAllString(markdown, fmt.Sprintf("${THE_START_OF_MATCH}<%s/${USERNAME}|@${USERNAME}>${THE_END_OF_MATCH}", gitHubURL))
5858

5959
// This makes sure all newlines are in the correct format, since this will otherwise cause issues with further replacements

slack_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ func TestSlackGithubUsername(t *testing.T) {
118118
assert := assert.New(t)
119119

120120
assert.Equal("<https://github.com/eritikass|@eritikass>", Slack("@eritikass"))
121+
assert.Equal("<https://github.com/roman-shandurenko|@roman-shandurenko>", Slack("@roman-shandurenko"))
121122
assert.Equal("<https://github.com/someone2Awesome8|@someone2Awesome8>", Slack("@someone2Awesome8"))
123+
assert.Equal("<https://github.com/soXeo-ne2Awes-ome8|@soXeo-ne2Awes-ome8>", Slack("@soXeo-ne2Awes-ome8"))
122124
assert.Equal("example@example.com", Slack("example@example.com"))
123125
assert.Equal("foo <https://github.com/eritikass|@eritikass> booo!", Slack("foo @eritikass booo!"))
124126
}

0 commit comments

Comments
 (0)