@@ -65,7 +65,6 @@ import { usecveRecordStore, useErrorMessageStore } from '@/stores/cveRecord';
65
65
import { useGenericGlobalsStore } from ' @/stores/genericGlobals' ;
66
66
67
67
const cveIdRegex = / ^ CVE\p {Pd}(?<year>\d {4} )\p {Pd}(?<id>\d {4,} )$ / iu ;
68
- const wordRegex = / ^ [a-z0-9 ] + $ / i ;
69
68
70
69
// This is the current maximum supported length of the "suffix" portion of
71
70
// the CVE ID. The schema defines a suffix length up to 19, but code in
@@ -85,7 +84,6 @@ const searchOptionLabel = 'Search CVE List';
85
84
86
85
let prevSearchValue = ref (' ' );
87
86
let queryString = ref (' ' );
88
- let errorMessage = ref (' ' );
89
87
90
88
let cveGenericGlobalsStore = useGenericGlobalsStore ();
91
89
let cveRecordStore = usecveRecordStore ();
@@ -119,7 +117,7 @@ watch(
119
117
&& ! cveGenericGlobalsStore .isProductionWebsite )
120
118
searchType .value = legacyOptionLabel;
121
119
else if (route .query ? .query ) {
122
- queryString .value = route .query .query . trim () ;
120
+ queryString .value = route .query .query ;
123
121
validate ();
124
122
}
125
123
}
@@ -200,23 +198,17 @@ function validateQueryString() {
200
198
}
201
199
202
200
if (isSearch) {
201
+ if (! errorMessageStore .isErrorMessage ) {
203
202
204
- // Search: if the query string isn't a CVE ID and it doesn't just consist
205
- // of "typical" words (alphanumeric phrases), then it's an error.
206
-
207
- if (! cveIdMatch && ! wordRegex .test (searchValue)) {
208
- errorMessageStore .setErrorMessage (contentMessage);
209
- } else if (! errorMessage .value ) {
210
-
211
- // The provided search string is good.
203
+ // The search can proceed with the provided string.
212
204
cveListSearchStore .isSearchButtonDisabled = false ;
213
205
}
214
206
} else if (cveIdValid) {
215
207
216
208
// Legacy Find by CVE ID and it's in the correct format.
217
209
cveListSearchStore .isSearchButtonDisabled = false ;
218
210
219
- } else if (! errorMessage . value ) {
211
+ } else if (! errorMessageStore . isErrorMessage ) {
220
212
221
213
// Legacy Find by CVE ID but the query string is not a CVE ID.
222
214
errorMessageStore .cveIdFormatMessage ();
@@ -225,6 +217,25 @@ function validateQueryString() {
225
217
return ! cveListSearchStore .isSearchButtonDisabled ;
226
218
}
227
219
220
+ function normalizeSearchString () {
221
+
222
+ if (! searchTypeBoolean .value )
223
+ return
224
+
225
+ // Each search string is "normalized" by removing excess spaces (both at
226
+ // the beginning and end of the string, as well as compressing multiple
227
+ // spaces separating "words" to a single space). Dashes (em-, en-) that
228
+ // may have been pasted in from elsewhere (e.g., Word) are converted to
229
+ // the minus (hyphen) character.
230
+
231
+ let normalizedString = queryString .value .trim ().replace (/ \s + / g , ' ' );
232
+
233
+ normalizedString = normalizedString .replace (/ \p {Pd}/ g , ' -' );
234
+
235
+ if (normalizedString !== queryString .value )
236
+ queryString .value = normalizedString;
237
+ }
238
+
228
239
function onInputChange () {
229
240
// This function is called when the search string changes. The only purpose
230
241
// is to clear the way for the search if there's a value (it's not empty)
@@ -261,6 +272,8 @@ function validate() {
261
272
//
262
273
// Provided the search string is valid, the search is started.
263
274
275
+ normalizeSearchString ();
276
+
264
277
if (validateQueryString ()) {
265
278
try {
266
279
cveListSearchStore .isSearchButtonDisabled = true ;
0 commit comments