From a5b0445e02d19fbd47950c0462d23447f67a08eb Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 2 May 2016 11:53:47 +1000 Subject: [PATCH] FIX: never perform searches that bypass validation we must perform another isValidSearchTerm check when we are about to perform search cause the call is debounced --- .../discourse/widgets/search-menu.js.es6 | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 index e17c96e8e..b585e0e18 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 @@ -34,15 +34,22 @@ const SearchHelper = { const searchContext = contextEnabled ? widget.searchContext() : null; const fullSearchUrl = widget.fullSearchUrl(); - this._activeSearch = searchForTerm(term, { typeFilter, searchContext, fullSearchUrl }); - this._activeSearch.then(content => { - state.noResults = content.resultTypes.length === 0; - state.results = content; - }).finally(() => { + if (!isValidSearchTerm(term)) { + state.noResults = true; + state.results = []; state.loading = false; widget.scheduleRerender(); - this._activeSearch = null; - }); + } else { + this._activeSearch = searchForTerm(term, { typeFilter, searchContext, fullSearchUrl }); + this._activeSearch.then(content => { + state.noResults = content.resultTypes.length === 0; + state.results = content; + }).finally(() => { + state.loading = false; + widget.scheduleRerender(); + this._activeSearch = null; + }); + } } };