@@ -144,7 +144,7 @@ function startSearch() {
144144 if (cveGenericGlobalsStore .useSearch ) {
145145 cveListSearchStore .$reset ();
146146 cveListSearchStore .query = queryString .value ;
147- if (route? .name !== ' SearchResults' || ! route .query ? .query
147+ if (route .name !== ' SearchResults' || ! route .query ? .query
148148 || (route .query .query !== cveListSearchStore .query )) {
149149
150150 router .push ({name: ' SearchResults' ,
@@ -233,8 +233,10 @@ function normalizeSearchString() {
233233}
234234
235235function onInputChange () {
236+
236237 // This function is called when the search string changes. The only purpose
237- // is to clear the way for the search if there's a value (it's not empty)
238+ // is to clear the way for the search if there's a value (it's not empty),
239+ // it doesn't contain any characters not supported by the search,
238240 // and it's not the same as a "bad" value used in the previous search.
239241 // As long as this is the case, we enable the search, which will then check
240242 // the validity of the search string when initiated.
@@ -252,8 +254,12 @@ function onInputChange() {
252254 errorMessageStore .$reset ();
253255 cveListSearchStore .isSearchButtonDisabled = true ;
254256
255- } else if (cveListSearchStore .isSearchButtonDisabled
257+ } else if (! allValidCharacters (searchValue)) {
258+ cveListSearchStore .isSearchButtonDisabled = true ;
259+ }
260+ else if (cveListSearchStore .isSearchButtonDisabled
256261 && prevSearchValue .value !== searchValue) {
262+ errorMessageStore .$reset ();
257263 cveListSearchStore .isSearchButtonDisabled = false ;
258264 }
259265}
@@ -289,6 +295,29 @@ function validate() {
289295 }
290296}
291297
298+ function allValidCharacters (searchString ) {
299+
300+ // This function checks the given search string for the presence of
301+ // any characters that are not supported for the search operation.
302+ // True is returned if the string has no invalid characters, and false
303+ // otherwise. The error message is also set to indicate the invalid
304+ // characters found in the string.
305+ //
306+ // Leave out the asterisk (*) for the moment, just for testing purposes:
307+ const invalidCharacters = ' {}[]"\' `<>+=|\; !~^' .split (' ' );
308+
309+ const found = invalidCharacters .filter (i => searchString .includes (i));
310+
311+ if (found .length ) {
312+ const message = ' search string contains the following invalid '
313+ + ` character(s): ${ found .join (' ' )} ` ;
314+
315+ errorMessageStore .setErrorMessage (message);
316+ }
317+
318+ return found .length === 0 ;
319+ }
320+
292321function resetSearch () {
293322
294323 // This function performs some reset tasks for the search that are
@@ -297,7 +326,7 @@ function resetSearch() {
297326
298327 prevSearchValue .value = ' ' ;
299328
300- if (route? .name != ' home' || route? .query )
329+ if (route .name != ' home' || route .query )
301330 router .push ({name: ' home' , query: {}});
302331}
303332< / script>
0 commit comments