File tree Expand file tree Collapse file tree 2 files changed +20
-91
lines changed Expand file tree Collapse file tree 2 files changed +20
-91
lines changed Original file line number Diff line number Diff line change @@ -203,7 +203,7 @@ describe('VFS Utils', () => {
203
203
const parser = utils . parseFields ( ) ;
204
204
205
205
return expect ( parser ( {
206
- url : '/foo/?bar.s =baz&jazz.s =bass' ,
206
+ url : '/foo/?bar=baz&jazz=bass' ,
207
207
method : 'get'
208
208
} ) )
209
209
. resolves
@@ -246,65 +246,22 @@ describe('VFS Utils', () => {
246
246
247
247
test ( 'assembleQueryData' , ( ) => {
248
248
const result1 = utils . assembleQueryData ( {
249
- 'a.s' : 'b' ,
250
- 'b.a.s' : 'foo' ,
251
- 'b.b.a.s' : 'foo' ,
252
- 'b.b.b.s' : 'foo' ,
253
- 'b.b.c.s' : 'foo' ,
254
- 'b.b.d.s' : 'foo' ,
255
- 'b.b.e.s' : 'foo' ,
256
- 'c.n' : 'null' ,
257
- 'd.b' : 'true' ,
258
- 'e.i' : '1' ,
259
- 'f.u' : 'undefined'
260
- } ) ;
261
-
262
- const result2 = utils . assembleQueryData ( {
263
- 'a.0.s' : 'foo' ,
264
- 'a.1.s' : 'foo' ,
265
- 'b.0.s' : 'foo' ,
266
- 'b.1.s' : 'foo' ,
267
- 'b.a.s' : 'foo' ,
268
- 'c.a.s' : 'foo' ,
269
- 'c.b.0.s' : 'foo' ,
270
- 'c.b.1.s' : 'foo' ,
271
- 'c.c.0.s' : 'foo' ,
272
- 'c.c.1.s' : 'foo' ,
273
- 'c.c.a.s' : 'foo' ,
249
+ 'a' : 'b' ,
250
+ 'b' : '{"a":"foo"}' ,
251
+ 'c' : '{"a":false,"c":null,"d":1,"e":{"a":"foo"}}'
274
252
} ) ;
275
253
276
254
expect ( result1 ) . toEqual ( {
277
255
a : 'b' ,
278
256
b : {
279
- a : 'foo' ,
280
- b : {
281
- a : 'foo' ,
282
- b : 'foo' ,
283
- c : 'foo' ,
284
- d : 'foo' ,
285
- e : 'foo'
286
- }
287
- } ,
288
- c : null ,
289
- d : true ,
290
- e : 1 ,
291
- f : undefined
292
- } ) ;
293
-
294
- expect ( result2 ) . toEqual ( {
295
- a : [ 'foo' , 'foo' ] ,
296
- b :{
297
- '0' : 'foo' ,
298
- '1' : 'foo' ,
299
- 'a' : 'foo' ,
257
+ a : 'foo'
300
258
} ,
301
259
c : {
302
- a : 'foo' ,
303
- b : [ 'foo' , 'foo' ] ,
304
- c : {
305
- '0' : 'foo' ,
306
- '1' : 'foo' ,
307
- 'a' : 'foo'
260
+ a : false ,
261
+ c : null ,
262
+ d : 1 ,
263
+ e : {
264
+ a : 'foo'
308
265
}
309
266
}
310
267
} ) ;
Original file line number Diff line number Diff line change @@ -42,17 +42,6 @@ const errorCodes = {
42
42
EACCES : 401
43
43
} ;
44
44
45
- /**
46
- * A map of data types
47
- */
48
- const typeMap = {
49
- i : str => parseInt ( str , 10 ) ,
50
- s : str => str ,
51
- b : str => str === 'true' ,
52
- u : str => undefined ,
53
- n : str => null
54
- } ;
55
-
56
45
/**
57
46
* Gets prefix of a VFS path
58
47
*/
@@ -185,35 +174,18 @@ const mountpointResolver = core => async (path) => {
185
174
/*
186
175
* Assembles a given object query
187
176
*/
188
- const assembleQueryData = ( object ) => {
189
- const assembled = { } ;
190
- const keys = Object . keys ( object ) ;
191
-
192
- for ( let i = 0 ; i < keys . length ; i ++ ) {
193
- const key = keys [ i ] ;
194
- const dots = key . split ( '.' ) ;
195
- const type = dots [ dots . length - 1 ] ;
196
- dots . pop ( ) ;
197
-
198
- let last = assembled ;
199
- let parent = null ;
200
- for ( let j = 0 ; j < dots . length ; j ++ ) {
201
- const dot = dots [ j ] ;
202
- if ( j >= dots . length - 1 ) {
203
- if ( ! / ^ \d + $ / . test ( dot ) && Array . isArray ( last ) ) {
204
- last = Object . fromEntries ( last . map ( ( value , i ) => [ i , value ] ) ) ;
205
- parent [ dots [ j - 1 ] ] = last ;
206
- }
207
- last [ dot ] = typeMap [ type ] ( object [ key ] ) ;
208
- } else {
209
- last [ dot ] = last [ dot ] || ( / ^ \d + $ / . test ( dots [ j + 1 ] ) ? [ ] : { } ) ;
177
+ const assembleQueryData = ( data ) => {
178
+ const entries = Object
179
+ . entries ( data )
180
+ . map ( ( [ k , v ] ) => {
181
+ try {
182
+ return [ k , JSON . parse ( v ) ] ;
183
+ } catch ( e ) {
184
+ return [ k , v ] ;
210
185
}
186
+ } ) ;
211
187
212
- parent = last ;
213
- last = last [ dot ] ;
214
- }
215
- }
216
- return assembled ;
188
+ return Object . fromEntries ( entries ) ;
217
189
} ;
218
190
219
191
/*
You can’t perform that action at this time.
0 commit comments