[MM-17300] Do not add empty string as a keyword key (#11961)

* Do not add empty string as a keyword key

* Add unit test

* User assert lib over t.Fatal
This commit is contained in:
Miguel Alatzar
2019-08-30 06:49:31 +09:00
committed by Elias Nahum
parent 782375f5c7
commit 0cd3663d91
2 changed files with 26 additions and 1 deletions

View File

@@ -593,7 +593,9 @@ func (a *App) getMentionKeywordsInChannel(profiles map[string]*model.User, lookF
for _, k := range splitKeys {
// note that these are made lower case so that we can do a case insensitive check for them
key := strings.ToLower(k)
keywords[key] = append(keywords[key], id)
if key != "" {
keywords[key] = append(keywords[key], id)
}
}
}

View File

@@ -1150,6 +1150,29 @@ func TestGetMentionKeywords(t *testing.T) {
} else if _, ok := mentions["@here"]; ok {
t.Fatal("should not have mentioned any user with @here")
}
// user with empty mention keys
userNoMentionKeys := &model.User{
Id: model.NewId(),
FirstName: "First",
Username: "User",
NotifyProps: map[string]string{
"mention_keys": ",",
},
}
channelMemberNotifyPropsMapEmptyOff := map[string]model.StringMap{
userNoMentionKeys.Id: {
"ignore_channel_mentions": model.IGNORE_CHANNEL_MENTIONS_OFF,
},
}
profiles = map[string]*model.User{userNoMentionKeys.Id: userNoMentionKeys}
mentions = th.App.getMentionKeywordsInChannel(profiles, true, channelMemberNotifyPropsMapEmptyOff)
assert.Equal(t, 1, len(mentions), "should've returned one metion keyword")
ids, ok := mentions["@user"]
assert.True(t, ok)
assert.Equal(t, userNoMentionKeys.Id, ids[0], "should've returned mention key of @user")
}
func TestGetMentionsEnabledFields(t *testing.T) {