[PLT-7701] Fix emoji names that trigger mention (#7663)
* fix emoji names that trigger mention * remove regex and rearrange based on comment * make ":@here:" to not trigger a mention
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1d968eb55e
Коммит
f632232862
@@ -804,11 +804,16 @@ func GetExplicitMentions(message string, keywords map[string][]string) (map[stri
|
|||||||
message = removeCodeFromMessage(message)
|
message = removeCodeFromMessage(message)
|
||||||
|
|
||||||
for _, word := range strings.FieldsFunc(message, func(c rune) bool {
|
for _, word := range strings.FieldsFunc(message, func(c rune) bool {
|
||||||
// Split on any whitespace or punctuation that can't be part of an at mention
|
// Split on any whitespace or punctuation that can't be part of an at mention or emoji pattern
|
||||||
return !(c == '.' || c == '-' || c == '_' || c == '@' || unicode.IsLetter(c) || unicode.IsNumber(c))
|
return !(c == ':' || c == '.' || c == '-' || c == '_' || c == '@' || unicode.IsLetter(c) || unicode.IsNumber(c))
|
||||||
}) {
|
}) {
|
||||||
isMention := false
|
isMention := false
|
||||||
|
|
||||||
|
// skip word with format ':word:' with an assumption that it is an emoji format only
|
||||||
|
if word[0] == ':' && word[len(word)-1] == ':' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if word == "@here" {
|
if word == "@here" {
|
||||||
hereMentioned = true
|
hereMentioned = true
|
||||||
}
|
}
|
||||||
@@ -837,10 +842,10 @@ func GetExplicitMentions(message string, keywords map[string][]string) (map[stri
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ContainsAny(word, ".-") {
|
if strings.ContainsAny(word, ".-:") {
|
||||||
// This word contains a character that may be the end of a sentence, so split further
|
// This word contains a character that may be the end of a sentence, so split further
|
||||||
splitWords := strings.FieldsFunc(word, func(c rune) bool {
|
splitWords := strings.FieldsFunc(word, func(c rune) bool {
|
||||||
return c == '.' || c == '-'
|
return c == '.' || c == '-' || c == ':'
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, splitWord := range splitWords {
|
for _, splitWord := range splitWords {
|
||||||
|
|||||||
@@ -200,6 +200,30 @@ func TestGetExplicitMentions(t *testing.T) {
|
|||||||
if mentions, _, _, _, _ := GetExplicitMentions(message, keywords); len(mentions) != 1 || !mentions[id1] || mentions[id2] || mentions[id3] {
|
if mentions, _, _, _, _ := GetExplicitMentions(message, keywords); len(mentions) != 1 || !mentions[id1] || mentions[id2] || mentions[id3] {
|
||||||
t.Fatal("should've only mentioned aaa")
|
t.Fatal("should've only mentioned aaa")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message = ":smile:"
|
||||||
|
keywords = map[string][]string{"smile": {id1}, "smiley": {id2}, "smiley_cat": {id3}}
|
||||||
|
if mentions, _, _, _, _ := GetExplicitMentions(message, keywords); len(mentions) == 1 || mentions[id1] {
|
||||||
|
t.Fatal("should not mentioned smile")
|
||||||
|
}
|
||||||
|
|
||||||
|
message = "smile"
|
||||||
|
keywords = map[string][]string{"smile": {id1}, "smiley": {id2}, "smiley_cat": {id3}}
|
||||||
|
if mentions, _, _, _, _ := GetExplicitMentions(message, keywords); len(mentions) != 1 || !mentions[id1] || mentions[id2] || mentions[id3] {
|
||||||
|
t.Fatal("should've only mentioned smile")
|
||||||
|
}
|
||||||
|
|
||||||
|
message = ":smile"
|
||||||
|
keywords = map[string][]string{"smile": {id1}, "smiley": {id2}, "smiley_cat": {id3}}
|
||||||
|
if mentions, _, _, _, _ := GetExplicitMentions(message, keywords); len(mentions) != 1 || !mentions[id1] || mentions[id2] || mentions[id3] {
|
||||||
|
t.Fatal("should've only mentioned smile")
|
||||||
|
}
|
||||||
|
|
||||||
|
message = "smile:"
|
||||||
|
keywords = map[string][]string{"smile": {id1}, "smiley": {id2}, "smiley_cat": {id3}}
|
||||||
|
if mentions, _, _, _, _ := GetExplicitMentions(message, keywords); len(mentions) != 1 || !mentions[id1] || mentions[id2] || mentions[id3] {
|
||||||
|
t.Fatal("should've only mentioned smile")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetExplicitMentionsAtHere(t *testing.T) {
|
func TestGetExplicitMentionsAtHere(t *testing.T) {
|
||||||
@@ -230,7 +254,7 @@ func TestGetExplicitMentionsAtHere(t *testing.T) {
|
|||||||
"\\@here\\": true,
|
"\\@here\\": true,
|
||||||
"|@here|": true,
|
"|@here|": true,
|
||||||
";@here;": true,
|
";@here;": true,
|
||||||
":@here:": true,
|
":@here:": false, // This case shouldn't trigger a mention since it follows the format of reactions e.g. :word:
|
||||||
"'@here'": true,
|
"'@here'": true,
|
||||||
"\"@here\"": true,
|
"\"@here\"": true,
|
||||||
",@here,": true,
|
",@here,": true,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user