MM-46871: Add remining search parameters to be escaped (#20963)

The first try wasn't exhaustive. I was planning to use
1f933263e7/store/sqlstore/post_store.go (L1738-L1748) for this
but it also contained `@` which we don't want.

In the end, I just used a separate slice for all
the characters to be escaped.

https://mattermost.atlassian.net/browse/MM-46871

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2022-09-09 21:21:34 +05:30
коммит произвёл GitHub
родитель 8b328386c5
Коммит 8797bfcde7
2 изменённых файлов: 19 добавлений и 2 удалений

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

@@ -1503,8 +1503,11 @@ func generateSearchQuery(query sq.SelectBuilder, terms []string, fields []string
var dbSpecificTerm string
if isPostgreSQL {
// Escaping the : in case of a Postgres search.
term = strings.ReplaceAll(term, ":", "\\:")
// Refer to https://www.postgresql.org/docs/current/functions-textsearch.html for the list of operators.
for _, c := range []string{":", "(", ")", "<", "!", "|"} {
// Escaping the special chars in case of a Postgres search.
term = strings.ReplaceAll(term, c, "\\"+c)
}
}
for _, field := range fields {

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

@@ -2807,6 +2807,20 @@ func testUserStoreSearch(t *testing.T, ss store.Store) {
&model.UserSearchOptions{},
[]*model.User{},
},
{
"escape ( and )",
t1id,
"ji(bah)",
&model.UserSearchOptions{},
[]*model.User{},
},
{
"escape <",
t1id,
"ji(bah<",
&model.UserSearchOptions{},
[]*model.User{},
},
{
"wildcard search",
t1id,