@@ -144,7 +144,7 @@ function startSearch() {
144
144
if (cveGenericGlobalsStore .useSearch ) {
145
145
cveListSearchStore .$reset ();
146
146
cveListSearchStore .query = queryString .value ;
147
- if (route? .name !== ' SearchResults' || ! route .query ? .query
147
+ if (route .name !== ' SearchResults' || ! route .query ? .query
148
148
|| (route .query .query !== cveListSearchStore .query )) {
149
149
150
150
router .push ({name: ' SearchResults' ,
@@ -233,8 +233,10 @@ function normalizeSearchString() {
233
233
}
234
234
235
235
function onInputChange () {
236
+
236
237
// 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,
238
240
// and it's not the same as a "bad" value used in the previous search.
239
241
// As long as this is the case, we enable the search, which will then check
240
242
// the validity of the search string when initiated.
@@ -252,8 +254,12 @@ function onInputChange() {
252
254
errorMessageStore .$reset ();
253
255
cveListSearchStore .isSearchButtonDisabled = true ;
254
256
255
- } else if (cveListSearchStore .isSearchButtonDisabled
257
+ } else if (! allValidCharacters (searchValue)) {
258
+ cveListSearchStore .isSearchButtonDisabled = true ;
259
+ }
260
+ else if (cveListSearchStore .isSearchButtonDisabled
256
261
&& prevSearchValue .value !== searchValue) {
262
+ errorMessageStore .$reset ();
257
263
cveListSearchStore .isSearchButtonDisabled = false ;
258
264
}
259
265
}
@@ -289,6 +295,29 @@ function validate() {
289
295
}
290
296
}
291
297
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
+
292
321
function resetSearch () {
293
322
294
323
// This function performs some reset tasks for the search that are
@@ -297,7 +326,7 @@ function resetSearch() {
297
326
298
327
prevSearchValue .value = ' ' ;
299
328
300
- if (route? .name != ' home' || route? .query )
329
+ if (route .name != ' home' || route .query )
301
330
router .push ({name: ' home' , query: {}});
302
331
}
303
332
< / script>
0 commit comments