Skip to content

Commit 12e92db

Browse files
committed
cveRecordSearchModule: add allValidCharacters(); SearchResults: remove non-production warning about test data (incorrect)
1 parent 147d8b9 commit 12e92db

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

src/components/cveRecordSearchModule.vue

+33-4
Original file line numberDiff line numberDiff line change
@@ -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
235235
function 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+
292321
function 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>

src/views/CVERecord/SearchResults.vue

-11
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@
2626
<ServiceUnavailable></ServiceUnavailable>
2727
</div>
2828
<div v-else>
29-
<div v-if="!genericGlobalsStore.isProductionWebsite"
30-
class="notification is-warning is-light" role="alert">
31-
<div class="is-flex is-justify-content-center">
32-
<p id="alertIconCveRecordsRequestErrored" class="is-hidden">alert</p>
33-
<font-awesome-icon style="flex: 0 0 40px;" size="1x" icon="triangle-exclamation" role="alert"
34-
aria-labelledby="alertIconCveRecordsRequestErrored" aria-hidden="false" />
35-
<p>You are accessing data from
36-
{{ generalGlobalsStore.currentServicesUrl }}
37-
</p>
38-
</div>
39-
</div>
4029
<h2 class="title">Search Results</h2>
4130
<div class="mb-3" v-if="hasRecordData || hasIdData">
4231
<h3 class="title is-size-5 mb-2"> CVE {{ getRecordOrIdLabel }} Found</h3>

0 commit comments

Comments
 (0)