[MM-24526] Filter * characters from the search terms in DB (#14884)

Этот коммит содержится в:
Amarjeet Anand
2020-08-05 17:13:31 +05:30
коммит произвёл GitHub
родитель 7f64199a37
Коммит fb453d578f
4 изменённых файлов: 67 добавлений и 6 удалений

Просмотреть файл

@@ -76,3 +76,30 @@ func TestSanitizeSearchTerm(t *testing.T) {
result = sanitizeSearchTerm(term, "*")
require.Equal(t, result, expected)
}
func TestRemoveNonAlphaNumericUnquotedTerms(t *testing.T) {
const (
sep = " "
chineseHello = "你好"
japaneseHello = "こんにちは"
)
tests := []struct {
term string
want string
name string
}{
{term: "", want: "", name: "empty"},
{term: "h", want: "h", name: "singleChar"},
{term: "hello", want: "hello", name: "multiChar"},
{term: `hel*lo "**" **& hello`, want: `hel*lo "**" hello`, name: "quoted_unquoted_english"},
{term: japaneseHello + chineseHello, want: japaneseHello + chineseHello, name: "japanese_chinese"},
{term: japaneseHello + ` "*" ` + chineseHello, want: japaneseHello + ` "*" ` + chineseHello, name: `quoted_japanese_and_chinese`},
{term: japaneseHello + ` "*" &&* ` + chineseHello, want: japaneseHello + ` "*" ` + chineseHello, name: "quoted_unquoted_japanese_and_chinese"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := removeNonAlphaNumericUnquotedTerms(test.term, sep)
require.Equal(t, test.want, got)
})
}
}