Commit bec0679 1 parent 03b7458 commit bec0679 Copy full SHA for bec0679
File tree 2 files changed +24
-4
lines changed
2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -109,14 +109,22 @@ const getQueryString = query => {
109
109
const objParts = Object . keys ( query [ k ] ) . map ( objKey => {
110
110
const key = encode ( `${ k } [${ objKey } ]` ) ;
111
111
const value = encode ( query [ k ] [ objKey ] ) ;
112
- return `${ key } =${ value } ` ;
113
- } ) ;
114
112
115
- return objParts . length ? `${ objParts . join ( '&' ) } ` : '' ;
113
+ if ( value . length ) {
114
+ return `${ key } =${ value } ` ;
115
+ }
116
+
117
+ return null ;
118
+ } ) . filter ( part => part !== null ) ;
119
+
120
+ return objParts . length ? `${ objParts . join ( '&' ) } ` : null ;
116
121
} else {
117
122
const key = encode ( `${ k } ` ) ;
118
123
const value = encode ( query [ k ] ) ;
119
- return `${ key } =${ value } ` ;
124
+
125
+ if ( value . length ) {
126
+ return `${ key } =${ value } ` ;
127
+ }
120
128
}
121
129
122
130
return null ;
Original file line number Diff line number Diff line change @@ -134,6 +134,18 @@ describe( 'helper', () => {
134
134
expect ( getQueryString ( query ) ) . toBe ( expectedQueryString ) ;
135
135
} ) ;
136
136
137
+ it ( 'should work with an query item that has an empty value' , ( ) => {
138
+ const query = { foo : '' } ;
139
+ const expectedQueryString = '' ;
140
+ expect ( getQueryString ( query ) ) . toBe ( expectedQueryString ) ;
141
+ } ) ;
142
+
143
+ it ( 'should work with an query item that is an object and has an empty value' , ( ) => {
144
+ const query = { foo : { bar : '' } } ;
145
+ const expectedQueryString = '' ;
146
+ expect ( getQueryString ( query ) ) . toBe ( expectedQueryString ) ;
147
+ } ) ;
148
+
137
149
it ( 'should encode special characters' , ( ) => {
138
150
const query = { test : 'Rock & Roll' } ;
139
151
const expectedQueryString = '?test=Rock+%26+Roll' ;
You can’t perform that action at this time.
0 commit comments