11<template >
22 <div class =" field mt-1" >
3- <div class =" field has-addons mb-1" >
3+ <div class =" field has-addons" >
4+ <div class =" control" >
5+ <span v-if =" websiteEnv !== 'prd'" class =" select cve-search-selector" >
6+ <select v-model =" searchType" >
7+ <option >Search CVE List (Beta)</option >
8+ <option >Find a Test CVE Record/ID (Legacy)</option >
9+ </select >
10+ </span >
11+ </div >
412 <div class =" control is-expanded" >
5- <input v-model.trim =" queryString" @keyup.enter =" onKeyUpEnter" @keyup =" validateQueryString" type =" text" class =" input cve-id-input"
6- placeholder =" Enter keywords (e.g.: CVE ID, sql injection, etc.)" />
13+ <input v-if =" searchTypeBoolean" v-model.trim =" queryString" @keyup.enter =" onKeyUpEnter"
14+ @keyup =" validateQueryString" type =" text" class =" input cve-id-input"
15+ placeholder =" Enter keywords (e.g.: CVE ID, sql injection, etc.)" />
16+ <input v-else v-model =" cveId" @keyup.enter =" onKeyUpEnter" @keyup =" validateQueryString" @blur =" removeHelpText"
17+ type =" text" class =" input cve-id-input" placeholder =" Enter CVE ID (CVE-YYYY-NNNN)" />
718 </div >
819 <div class =" control" >
9- <button @click =" validate"
10- class =" button cve-button cve-button-accent-warm"
11- :class =" {'is-loading': cveListSearchStore.isSearching, 'disabled': cveListSearchStore.isSeachButtonDisabled}"
20+ <button @click =" validate" class =" button cve-button cve-button-accent-warm"
21+ :class =" { 'is-loading': cveListSearchStore.isSearching, 'disabled': cveListSearchStore.isSeachButtonDisabled }"
1222 :aria-disabled =" cveListSearchStore.isSeachButtonDisabled" >
13- Search {{ websiteEnv === 'test' ? 'CVE List in Test' : ''}}
23+ Search {{ websiteEnv === 'test' ? 'CVE List in Test' : '' }}
1424 </button >
1525 </div >
1626 </div >
1727 <div class =" notification is-warning is-light" role =" alert" v-if =" errorMessage.length > 0" >
1828 <div class =" is-flex is-align-content-flex-start" >
1929 <p id =" alertIcon" class =" is-hidden" >alert</p >
20- <font-awesome-icon style =" flex : 0 0 40px ; margin-top :3px " size =" lg" icon =" exclamation-triangle" role =" alert"
30+ <font-awesome-icon style =" flex : 0 0 40px ; margin-top :3px " size =" lg" icon =" exclamation-triangle" role =" alert"
2131 aria-labelledby =" alertIcon" aria-hidden =" false" />
22- <p class =" cve-help-text" >
23- {{ errorMessage}}
24- <router-link to =" /About/Process#request" > Learn more</router-link >
25- </p >
32+ <p class =" cve-help-text" >
33+ {{ errorMessage }}
34+ <router-link to =" /About/Process#request" > Learn more</router-link >
35+ </p >
2636 </div >
2737 </div >
2838 </div >
3242import { useCveListSearchStore } from ' @/stores/cveListSearch' ;
3343import { computed , ref , watch } from ' vue' ;
3444import { useRoute , useRouter } from ' vue-router' ;
45+ // Legacy Search Import
46+ import { usecveRecordStore } from ' @/stores/cveRecord' ;
47+ import { useGenericGlobalsStore } from ' @/stores/genericGlobals' ;
48+
3549let cveListSearchStore = useCveListSearchStore ();
3650const route = useRoute ();
3751const router = useRouter ();
3852
3953let queryString = ref (' ' );
4054let errorMessage = ref (' ' );
4155
56+ let cveGenericGlobalsStore = useGenericGlobalsStore ();
57+ let cveRecordStore = usecveRecordStore ();
58+ let searchType = ref (' Search CVE List (Beta)' );
59+ let cveId = cveRecordStore .cveId ;
60+
61+ // this seems redundant, but it fixes an edge case.
62+ // if a user searches for a particular field, then on the results page flips the toggle, THEN refreshes without searching, this will keep the correct helper text showing.
63+ let searchTypeBoolean = computed (() => {
64+ return searchType .value == ' Search CVE List (Beta)' ? true : false ;
65+ });
66+
4267watch (
4368 () => route .query ,
4469 () => {
45- if (route .query ? .query ){
70+ if (route .query ? .query ) {
4671 queryString .value = route .query .query .trim ();
4772 validate ();
4873 } else {
@@ -54,33 +79,66 @@ watch(
5479
5580
5681function startSearch () {
57- if (queryString .value !== cveListSearchStore .query ) {
58- cveListSearchStore .$reset ();
59- cveListSearchStore .query = queryString .value ;
82+ // We only want to flip the search item _When we actually do a search_ otherwise we should default back to what we were on a page refresh
83+ if (searchTypeBoolean .value ) {
84+ cveGenericGlobalsStore .setUseSearch (true );
85+ cveGenericGlobalsStore .setCurrentServicesUrl (` https://${ import .meta.env.VITE_CVE_SERVICES_BASE_URL}` )
86+ }
87+ else {
88+ cveGenericGlobalsStore.setUseSearch(false);
89+ cveGenericGlobalsStore.setCurrentServicesUrl(cveGenericGlobalsStore.cveServiceTestBaseUrl)
90+ }
91+ if (cveGenericGlobalsStore.useSearch) {
92+ if (queryString.value !== cveListSearchStore.query) {
93+ cveListSearchStore.$reset();
94+ cveListSearchStore.query = queryString.value;
6095 router.push({
6196 name: 'SearchResults',
62- query: {query: cveListSearchStore .query }
97+ query: { query: cveListSearchStore.query }
6398 });
6499 cveListSearchStore.search();
100+ }
101+ } else {
102+ const lookupPath = ` /CVERecord?id=${cveId }` ;
103+ router.push(lookupPath)
65104 }
105+
66106}
67107
68108function validateQueryString() {
69- const alphaNumericDashPattern = new RegExp (/ ^ [a-zA-Z0-9 ] + $ / , ' i' ).test (queryString .value );
70- const cveIdPattern = new RegExp (/ ^ CVE-\d {4} -\d {4,7} $ / , ' i' ).test (queryString .value );
71-
72- if (queryString .value .length > 0 && ! alphaNumericDashPattern && ! cveIdPattern) {
73- cveListSearchStore .isSeachButtonDisabled = true ;
74- errorMessage .value = ' Only letters, numbers, and CVE IDs (CVE-YYYY-NNNN) are allowed.' ;
75- cveListSearchStore .showHelpText = true ;
76- } else if (queryString .value .length === 0 ) {
77- cveListSearchStore .isSeachButtonDisabled = true ;
78- errorMessage .value = ' ' ;
79- cveListSearchStore .showHelpText = false ;
109+ if (searchTypeBoolean.value) {
110+ const alphaNumericDashPattern = new RegExp(/^[a-zA-Z0-9 ]+$/, 'i').test(queryString.value);
111+ const cveIdPattern = new RegExp(/^CVE-\d {4}-\d {4,7}$/, 'i').test(queryString.value);
112+
113+ if (queryString.value.length > 0 && !alphaNumericDashPattern && !cveIdPattern) {
114+ cveListSearchStore.isSeachButtonDisabled = true;
115+ errorMessage.value = 'Only letters, numbers, and CVE IDs (CVE-YYYY-NNNN) are allowed.';
116+ cveListSearchStore.showHelpText = true;
117+ } else if (queryString.value.length === 0) {
118+ cveListSearchStore.isSeachButtonDisabled = true;
119+ errorMessage.value = '';
120+ cveListSearchStore.showHelpText = false;
121+ } else {
122+ cveListSearchStore.isSeachButtonDisabled = false;
123+ errorMessage.value = '';
124+ cveListSearchStore.showHelpText = false;
125+ }
80126 } else {
81- cveListSearchStore .isSeachButtonDisabled = false ;
82- errorMessage .value = ' ' ;
83- cveListSearchStore .showHelpText = false ;
127+ //Basic Checking
128+ const cveIdPattern = new RegExp(/^CVE-\d {4}-\d {4,7}$/, 'i').test(cveId);
129+ if (cveId.length > 0 && !cveIdPattern) {
130+ cveListSearchStore.isSeachButtonDisabled = true;
131+ errorMessage.value = 'Only CVE IDs (CVE-YYYY-NNNN) are allowed.';
132+ cveListSearchStore.showHelpText = true;
133+ } else if (cveId.length === 0) {
134+ cveListSearchStore.isSeachButtonDisabled = true;
135+ errorMessage.value = '';
136+ cveListSearchStore.showHelpText = false;
137+ } else {
138+ cveListSearchStore.isSeachButtonDisabled = false;
139+ errorMessage.value = '';
140+ cveListSearchStore.showHelpText = false;
141+ }
84142 }
85143}
86144
@@ -89,10 +147,16 @@ function onKeyUpEnter() {
89147}
90148
91149function validate() {
150+
92151 validateQueryString();
93- if (! cveListSearchStore .isSeachButtonDisabled ) {
152+ if (cveGenericGlobalsStore.useSearch) {
153+ if (!cveListSearchStore.isSeachButtonDisabled) {
154+ startSearch();
155+ }
156+ } else {
94157 startSearch();
95158 }
159+
96160}
97161
98162const websiteEnv = computed(() => {
@@ -111,7 +175,7 @@ const websiteEnv = computed(() => {
111175
112176.notification {
113177 margin: 0 0 2px 0 !important;
114- padding: 2px 10px 2px 10px ! important;
178+ padding: 2px 10px 2px 10px !important;
115179}
116180
117181@media screen and (min-width: $desktop) {
0 commit comments