11<template >
22 <div class =" field mt-1" >
3- <div class =" field has-addons mb-1" >
4- <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.)" />
7- </div >
8- <div class =" control" >
9- <button @click =" validate"
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 >
12+ <div class =" control is-expanded" >
13+ <input v-if =" searchTypeBoolean" v-model.trim =" queryString" @keyup.enter =" onKeyUpEnter" @keyup =" validateQueryString" type =" text" class =" input cve-id-input"
14+ placeholder =" Enter keywords (e.g.: CVE ID, sql injection, etc.)" />
15+ <input v-else v-model =" cveId" @keyup.enter =" onKeyUpEnter" @keyup =" validateQueryString" @blur =" removeHelpText" type =" text" class =" input cve-id-input"
16+ placeholder =" Enter CVE ID (CVE-YYYY-NNNN)" />
17+ </div >
18+ <div class =" control" >
19+ <button @click =" validate"
1020 class =" button cve-button cve-button-accent-warm"
1121 :class =" {'is-loading': cveListSearchStore.isSearching, 'disabled': cveListSearchStore.isSeachButtonDisabled}"
1222 :aria-disabled =" cveListSearchStore.isSeachButtonDisabled" >
1323 Search {{ websiteEnv === 'test' ? 'CVE List in Test' : ''}}
1424 </button >
15- </div >
1625 </div >
26+ </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 >
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 () => {
@@ -54,7 +79,17 @@ watch(
5479
5580
5681function startSearch () {
57- if (queryString .value !== cveListSearchStore .query ) {
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("https://cveawg-test.mitre.org")
90+ }
91+ if (cveGenericGlobalsStore.useSearch) {
92+ if (queryString.value !== cveListSearchStore.query) {
5893 cveListSearchStore.$reset();
5994 cveListSearchStore.query = queryString.value;
6095 router.push({
@@ -63,24 +98,47 @@ function startSearch() {
6398 });
6499 cveListSearchStore.search();
65100 }
101+ } else {
102+ const lookupPath = ` /CVERecord?id=${cveId }` ;
103+ router.push(lookupPath)
104+ }
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(() => {
@@ -119,4 +183,5 @@ const websiteEnv = computed(() => {
119183 width: 470px;
120184 }
121185}
186+
122187</style>
0 commit comments