From fa0aecce1eb845cb3c7f31797ad5554ddda62e8e Mon Sep 17 00:00:00 2001 From: Daniel Fiori Date: Mon, 12 Nov 2018 15:54:12 -0500 Subject: [PATCH] Ignore "@" sign at the beginning of user searches (#9780) This trims the "@" symbol from the begging of the search term before executing the query. --- store/sqlstore/user_store.go | 2 +- store/storetest/user_store.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 02092d2240..1b46ae8077 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -1166,7 +1166,7 @@ func generateSearchQuery(searchQuery string, terms []string, fields []string, pa } } searchTerms = append(searchTerms, fmt.Sprintf("(%s)", strings.Join(searchFields, " OR "))) - parameters[fmt.Sprintf("Term%d", i)] = fmt.Sprintf("%s%%", term) + parameters[fmt.Sprintf("Term%d", i)] = fmt.Sprintf("%s%%", strings.TrimLeft(term, "@")) } searchClause := strings.Join(searchTerms, " AND ") diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index a3c1af5a35..390adf3bca 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -1658,6 +1658,16 @@ func testUserStoreSearch(t *testing.T, ss store.Store) { }, []*model.User{u1}, }, + { + "leading @ should be ignored", + tid, + "@jimb", + &model.UserSearchOptions{ + AllowFullNames: true, + Limit: model.USER_SEARCH_DEFAULT_LIMIT, + }, + []*model.User{u1}, + }, } for _, testCase := range testCases {