From bb9bde1c19e175219615bace44d13f2e251f0c1f Mon Sep 17 00:00:00 2001 From: ioancole Date: Fri, 11 Sep 2020 01:12:32 +0800 Subject: [PATCH] Encode automplete search string and don't autocomplete for empty query --- ui/redux/actions/search.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/redux/actions/search.js b/ui/redux/actions/search.js index a7356c16e..5b715d5fd 100644 --- a/ui/redux/actions/search.js +++ b/ui/redux/actions/search.js @@ -45,7 +45,7 @@ export const getSearchSuggestions = (value: string) => (dispatch: Dispatch, getS return; } - fetch(`${CONNECTION_STRING}autocomplete?s=${searchValue}`) + fetch(`${CONNECTION_STRING}autocomplete?s=${encodeURIComponent(searchValue)}`) .then(handleFetchResponse) .then(apiSuggestions => { dispatch({ @@ -72,6 +72,8 @@ export const doUpdateSearchQuery = (query: string, shouldSkipSuggestions: ?boole data: { query }, }); + if (!query) return; + // Don't fetch new suggestions if the user just added a space if (!query.endsWith(' ') || !shouldSkipSuggestions) { throttledSearchSuggestions(dispatch, query);