From dcc20167557aa1f85943410a898baf62f142bfde Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Wed, 20 Dec 2017 19:29:43 +0000 Subject: [PATCH] PLT-8354: Fix user search error when terms end up as empty space. (#7984) --- store/sqlstore/user_store.go | 2 +- store/storetest/user_store.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 09b1ce1bea..5ecc1fdda8 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -1078,7 +1078,7 @@ func (us SqlUserStore) performSearch(searchQuery string, term string, options ma searchQuery = strings.Replace(searchQuery, "INACTIVE_CLAUSE", "AND Users.DeleteAt = 0", 1) } - if term == "" { + if strings.TrimSpace(term) == "" { searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1) } else { isPostgreSQL := us.DriverName() == model.DATABASE_DRIVER_POSTGRES diff --git a/store/storetest/user_store.go b/store/storetest/user_store.go index ce1fb4a868..3b2bf502bb 100644 --- a/store/storetest/user_store.go +++ b/store/storetest/user_store.go @@ -8,6 +8,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" ) @@ -1817,6 +1819,10 @@ func testUserStoreSearch(t *testing.T, ss store.Store) { t.Fatal("should have found user") } } + + // Check PLT-8354 - search that ends up with just space for terms doesn't error. + r1 := <-ss.User().SearchWithoutTeam("* ", searchOptions) + assert.Nil(t, r1.Err) } func testUserStoreSearchWithoutTeam(t *testing.T, ss store.Store) {