diff --git a/app/notification.go b/app/notification.go index 3bae73d1c2..00813963b7 100644 --- a/app/notification.go +++ b/app/notification.go @@ -486,7 +486,7 @@ func GetExplicitMentions(post *model.Post, keywords map[string][]string) *Explic foundWithoutSuffix := false wordWithoutSuffix := word - for strings.LastIndexAny(wordWithoutSuffix, ".-:_") != -1 { + for len(wordWithoutSuffix) > 0 && strings.LastIndexAny(wordWithoutSuffix, ".-:_") == (len(wordWithoutSuffix)-1) { wordWithoutSuffix = wordWithoutSuffix[0 : len(wordWithoutSuffix)-1] if checkForMention(wordWithoutSuffix) { diff --git a/app/notification_test.go b/app/notification_test.go index 3d2333f638..cde212ba97 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -530,6 +530,20 @@ func TestGetExplicitMentions(t *testing.T) { HereMentioned: true, }, }, + "Name on keywords is a prefix of a mention": { + Message: "@other @test-two", + Keywords: map[string][]string{"@test": {model.NewId()}}, + Expected: &ExplicitMentions{ + OtherPotentialMentions: []string{"other", "test-two"}, + }, + }, + "Name on mentions is a prefix of other mention": { + Message: "@other-one @other @other-two", + Keywords: nil, + Expected: &ExplicitMentions{ + OtherPotentialMentions: []string{"other-one", "other", "other-two"}, + }, + }, } { t.Run(name, func(t *testing.T) {