@@ -5,7 +5,30 @@ class cveClient {
55 this . key = key ;
66 this . url = url ;
77 this . user_path = "/org/" + this . org + "/user/" + this . user ;
8- this . _version = "1.0.25" ;
8+ this . _version = "1.0.26" ;
9+ }
10+ /* Safely build query string */
11+ _buildQuery ( qvars ) {
12+ if ( ! qvars ) return "" ;
13+
14+ const params = new URLSearchParams ( ) ;
15+
16+ Object . entries ( qvars ) . forEach ( ( [ key , val ] ) => {
17+ /* Skip only null/undefined */
18+ if ( val == null ) return ;
19+ /* Handle arrays (common in APIs) */
20+ if ( Array . isArray ( val ) ) {
21+ val . forEach ( v => {
22+ if ( v != null ) params . append ( key , String ( v ) ) ;
23+ } ) ;
24+ return ;
25+ }
26+
27+ /* Normalize everything else */
28+ params . append ( key , String ( val ) ) ;
29+ } ) ;
30+
31+ return params . toString ( ) ;
932 }
1033 /* PUT /cve/{id}/adp — the only ADP endpoint per CVE Services API spec
1134 See https://cveawg.mitre.org/api-docs/ */
@@ -139,21 +162,13 @@ class cveClient {
139162 if ( ! opts ) {
140163 opts = { method :'GET' } ;
141164 }
142- if ( qvars ) {
143- var qstr = new URLSearchParams ( ) ;
144- Object . keys ( qvars ) . forEach ( function ( x ) {
145- /* Remove empty values in query_string
146- strange issue #11 when changing user's information
147- see https://github.com/CERTCC/cveClient/issues/11
148- */
149- if ( qvars [ x ] != "" )
150- qstr . append ( x , qvars [ x ] ) ;
151- } ) ;
152- url . search = qstr . toString ( ) ;
165+ const qs = this . _buildQuery ( qvars ) ;
166+ if ( qs ) {
167+ url . search = qs ;
153168 }
154169 if ( ! ( 'headers' in opts ) )
155170 opts . headers = { } ;
156- opts . headers = Object . assign ( { } , opts . headers ,
171+ opts . headers = Object . assign ( { } , opts . headers || { } ,
157172 { 'CVE-API-KEY' : this . key ,
158173 'CVE-API-ORG' : this . org ,
159174 'CVE-API-USER' : this . user } ) ;
0 commit comments