@@ -64,7 +64,6 @@ import { useErrorMessageStore } from '@/stores/cveRecord';
6464import { useGenericGlobalsStore } from ' @/stores/genericGlobals' ;
6565
6666const cveIdRegex = / ^ CVE\p {Pd}(?<year>\d {4} )\p {Pd}(?<id>\d {4,} )$ / iu ;
67- const wordRegex = / ^ [a-z0-9 ] + $ / i ;
6867
6968// This is the current maximum supported length of the "suffix" portion of
7069// the CVE ID. The schema defines a suffix length up to 19, but code in
@@ -84,7 +83,6 @@ const searchOptionLabel = 'Search CVE List';
8483
8584let prevSearchValue = ref (' ' );
8685let queryString = ref (' ' );
87- let errorMessage = ref (' ' );
8886
8987let cveGenericGlobalsStore = useGenericGlobalsStore ();
9088let searchType = ref (' ' );
@@ -121,7 +119,7 @@ watch(
121119 && (route .query ? .prod ?? ' false' ) !== ' true' )
122120 searchType .value = legacyOptionLabel;
123121 else if (route .query ? .query ) {
124- queryString .value = route .query .query . trim () ;
122+ queryString .value = route .query .query ;
125123 validate ();
126124 }
127125 }
@@ -197,23 +195,17 @@ function validateQueryString() {
197195 }
198196
199197 if (isSearch) {
198+ if (! errorMessageStore .isErrorMessage ) {
200199
201- // Search: if the query string isn't a CVE ID and it doesn't just consist
202- // of "typical" words (alphanumeric phrases), then it's an error.
203-
204- if (! cveIdMatch && ! wordRegex .test (searchValue)) {
205- errorMessageStore .setErrorMessage (contentMessage);
206- } else if (! errorMessage .value ) {
207-
208- // The provided search string is good.
200+ // The search can proceed with the provided string.
209201 cveListSearchStore .isSearchButtonDisabled = false ;
210202 }
211203 } else if (cveIdValid) {
212204
213205 // Legacy Find by CVE ID and it's in the correct format.
214206 cveListSearchStore .isSearchButtonDisabled = false ;
215207
216- } else if (! errorMessage . value ) {
208+ } else if (! errorMessageStore . isErrorMessage ) {
217209
218210 // Legacy Find by CVE ID but the query string is not a CVE ID.
219211 errorMessageStore .cveIdFormatMessage ();
@@ -222,6 +214,25 @@ function validateQueryString() {
222214 return ! cveListSearchStore .isSearchButtonDisabled ;
223215}
224216
217+ function normalizeSearchString () {
218+
219+ if (! searchTypeBoolean .value )
220+ return
221+
222+ // Each search string is "normalized" by removing excess spaces (both at
223+ // the beginning and end of the string, as well as compressing multiple
224+ // spaces separating "words" to a single space). Dashes (em-, en-) that
225+ // may have been pasted in from elsewhere (e.g., Word) are converted to
226+ // the minus (hyphen) character.
227+
228+ let normalizedString = queryString .value .trim ().replace (/ \s + / g , ' ' );
229+
230+ normalizedString = normalizedString .replace (/ \p {Pd}/ g , ' -' );
231+
232+ if (normalizedString !== queryString .value )
233+ queryString .value = normalizedString;
234+ }
235+
225236function onInputChange () {
226237 // This function is called when the search string changes. The only purpose
227238 // is to clear the way for the search if there's a value (it's not empty)
@@ -258,6 +269,8 @@ function validate() {
258269 //
259270 // Provided the search string is valid, the search is started.
260271
272+ normalizeSearchString ();
273+
261274 if (validateQueryString ()) {
262275 try {
263276 cveListSearchStore .isSearchButtonDisabled = true ;
0 commit comments