[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
Этот коммит содержится в:
коммит произвёл
Elias Nahum
родитель
782375f5c7
Коммит
0cd3663d91
@@ -593,7 +593,9 @@ func (a *App) getMentionKeywordsInChannel(profiles map[string]*model.User, lookF
|
|||||||
for _, k := range splitKeys {
|
for _, k := range splitKeys {
|
||||||
// note that these are made lower case so that we can do a case insensitive check for them
|
// note that these are made lower case so that we can do a case insensitive check for them
|
||||||
key := strings.ToLower(k)
|
key := strings.ToLower(k)
|
||||||
keywords[key] = append(keywords[key], id)
|
if key != "" {
|
||||||
|
keywords[key] = append(keywords[key], id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1150,6 +1150,29 @@ func TestGetMentionKeywords(t *testing.T) {
|
|||||||
} else if _, ok := mentions["@here"]; ok {
|
} else if _, ok := mentions["@here"]; ok {
|
||||||
t.Fatal("should not have mentioned any user with @here")
|
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) {
|
func TestGetMentionsEnabledFields(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user