MM-9868 Fixed mentioning users when followed by multiple periods (#8548)
* MM-9868 Fixed mentioning users when followed by multiple periods * Added additional unit test * Added comment to clarify test purpose
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cffb891854
Коммит
088f76ad6e
@@ -892,8 +892,17 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove trailing '.', as that is the end of a sentence
|
// remove trailing '.', as that is the end of a sentence
|
||||||
word = strings.TrimSuffix(word, ".")
|
foundWithSuffix := false
|
||||||
if checkForMention(word) {
|
|
||||||
|
for strings.HasSuffix(word, ".") {
|
||||||
|
word = strings.TrimSuffix(word, ".")
|
||||||
|
if checkForMention(word) {
|
||||||
|
foundWithSuffix = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if foundWithSuffix {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -344,6 +344,45 @@ func TestGetExplicitMentions(t *testing.T) {
|
|||||||
ChannelMentioned: true,
|
ChannelMentioned: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The following tests cover cases where the message mentions @user.name, so we shouldn't assume that
|
||||||
|
// the user might be intending to mention some @user that isn't in the channel.
|
||||||
|
"Don't include potential mention that's part of an actual mention (without trailing period)": {
|
||||||
|
Message: "this is an message for @user.name",
|
||||||
|
Keywords: map[string][]string{"@user.name": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Don't include potential mention that's part of an actual mention (with trailing period)": {
|
||||||
|
Message: "this is an message for @user.name.",
|
||||||
|
Keywords: map[string][]string{"@user.name": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Don't include potential mention that's part of an actual mention (with multiple trailing periods)": {
|
||||||
|
Message: "this is an message for @user.name...",
|
||||||
|
Keywords: map[string][]string{"@user.name": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Don't include potential mention that's part of an actual mention (containing and followed by multiple periods)": {
|
||||||
|
Message: "this is an message for @user...name...",
|
||||||
|
Keywords: map[string][]string{"@user...name": {id1}},
|
||||||
|
Expected: &ExplicitMentions{
|
||||||
|
MentionedUserIds: map[string]bool{
|
||||||
|
id1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
m := GetExplicitMentions(tc.Message, tc.Keywords)
|
m := GetExplicitMentions(tc.Message, tc.Keywords)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user