diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index b5b60c3d57..8a359ed870 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -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 { diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index 14cde98222..cef2ce02e8 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -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,