@@ -63,7 +63,6 @@ import { usecveRecordStore, useErrorMessageStore } from '@/stores/cveRecord';
6363import { useGenericGlobalsStore } from ' @/stores/genericGlobals' ;
6464
6565const cveIdRegex = / ^ CVE\p {Pd}(?<year>\d {4} )\p {Pd}(?<id>\d {4,} )$ / iu ;
66- const wordRegex = / ^ [a-z0-9 ] + $ / i ;
6766
6867const isProductionWebsite = import .meta.env.VITE_WEBSITE_ENVIRONMENT === ' prd' ;
6968
@@ -85,7 +84,6 @@ const searchOptionLabel = 'Search CVE List';
8584
8685let prevSearchValue = ref (' ' );
8786let queryString = ref (' ' );
88- let errorMessage = ref (' ' );
8987
9088let cveGenericGlobalsStore = useGenericGlobalsStore ();
9189let cveRecordStore = usecveRecordStore ();
@@ -118,7 +116,7 @@ watch(
118116 if (route? .name === cveRecordRouteName && ! isProductionWebsite)
119117 searchType .value = legacyOptionLabel;
120118 else if (route .query ? .query ) {
121- queryString .value = route .query .query . trim () ;
119+ queryString .value = route .query .query ;
122120 validate ();
123121 }
124122 }
@@ -201,23 +199,17 @@ function validateQueryString() {
201199 }
202200
203201 if (isSearch) {
202+ if (!errorMessageStore.isErrorMessage) {
204203
205- // Search: if the query string isn't a CVE ID and it doesn't just consist
206- // of "typical" words (alphanumeric phrases), then it's an error.
207-
208- if (!cveIdMatch && !wordRegex.test(searchValue)) {
209- errorMessageStore.setErrorMessage(contentMessage);
210- } else if (!errorMessage.value) {
211-
212- // The provided search string is good.
204+ // The search can proceed with the provided string.
213205 cveListSearchStore.isSearchButtonDisabled = false;
214206 }
215207 } else if (cveIdValid) {
216208
217209 // Legacy Find by CVE ID and it's in the correct format.
218210 cveListSearchStore.isSearchButtonDisabled = false;
219211
220- } else if (!errorMessage.value ) {
212+ } else if (!errorMessageStore.isErrorMessage ) {
221213
222214 // Legacy Find by CVE ID but the query string is not a CVE ID.
223215 errorMessageStore.cveIdFormatMessage();
@@ -226,6 +218,25 @@ function validateQueryString() {
226218 return !cveListSearchStore.isSearchButtonDisabled;
227219}
228220
221+ function normalizeSearchString() {
222+
223+ if (!searchTypeBoolean.value)
224+ return
225+
226+ // Each search string is "normalized" by removing excess spaces (both at
227+ // the beginning and end of the string, as well as compressing multiple
228+ // spaces separating "words" to a single space). Dashes (em-, en-) that
229+ // may have been pasted in from elsewhere (e.g., Word) are converted to
230+ // the minus (hyphen) character.
231+
232+ let normalizedString = queryString.value.trim().replace(/\s +/g, ' ');
233+
234+ normalizedString = normalizedString.replace(/\p {Pd}/g, '-');
235+
236+ if (normalizedString !== queryString.value)
237+ queryString.value = normalizedString;
238+ }
239+
229240function onInputChange() {
230241 // This function is called when the search string changes. The only purpose
231242 // is to clear the way for the search if there's a value (it's not empty)
@@ -262,6 +273,8 @@ function validate() {
262273 //
263274 // Provided the search string is valid, the search is started.
264275
276+ normalizeSearchString();
277+
265278 if (validateQueryString()) {
266279 try {
267280 cveListSearchStore.isSearchButtonDisabled = true;
0 commit comments