File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ describe('VFS Utils', () => {
245
245
} ) ;
246
246
247
247
test ( 'assembleQueryData' , ( ) => {
248
- const result = utils . assembleQueryData ( {
248
+ const result1 = utils . assembleQueryData ( {
249
249
'a' : 'b' ,
250
250
'b.a' : 'foo' ,
251
251
'b.b.a' : 'foo' ,
@@ -258,7 +258,21 @@ describe('VFS Utils', () => {
258
258
'e' : '1'
259
259
} ) ;
260
260
261
- expect ( result ) . toEqual ( {
261
+ const result2 = utils . assembleQueryData ( {
262
+ 'a.0' : 'foo' ,
263
+ 'a.1' : 'foo' ,
264
+ 'b.0' : 'foo' ,
265
+ 'b.1' : 'foo' ,
266
+ 'b.a' : 'foo' ,
267
+ 'c.a' : 'foo' ,
268
+ 'c.b.0' : 'foo' ,
269
+ 'c.b.1' : 'foo' ,
270
+ 'c.c.0' : 'foo' ,
271
+ 'c.c.1' : 'foo' ,
272
+ 'c.c.a' : 'foo' ,
273
+ } ) ;
274
+
275
+ expect ( result1 ) . toEqual ( {
262
276
a : 'b' ,
263
277
b : {
264
278
a : 'foo' ,
@@ -274,5 +288,23 @@ describe('VFS Utils', () => {
274
288
d : 'true' ,
275
289
e : '1'
276
290
} ) ;
291
+
292
+ expect ( result2 ) . toEqual ( {
293
+ a : [ 'foo' , 'foo' ] ,
294
+ b :{
295
+ '0' : 'foo' ,
296
+ '1' : 'foo' ,
297
+ 'a' : 'foo' ,
298
+ } ,
299
+ c : {
300
+ a : 'foo' ,
301
+ b : [ 'foo' , 'foo' ] ,
302
+ c : {
303
+ '0' : 'foo' ,
304
+ '1' : 'foo' ,
305
+ 'a' : 'foo'
306
+ }
307
+ }
308
+ } ) ;
277
309
} ) ;
278
310
} ) ;
Original file line number Diff line number Diff line change @@ -183,14 +183,20 @@ const assembleQueryData = (object) => {
183
183
const dots = key . split ( '.' ) ;
184
184
185
185
let last = assembled ;
186
+ let parent = null ;
186
187
for ( let j = 0 ; j < dots . length ; j ++ ) {
187
188
const dot = dots [ j ] ;
188
189
if ( j >= dots . length - 1 ) {
190
+ if ( ! / ^ \d + $ / . test ( dot ) && Array . isArray ( last ) ) {
191
+ last = Object . fromEntries ( last . map ( ( value , i ) => [ i , value ] ) ) ;
192
+ parent [ dots [ j - 1 ] ] = last ;
193
+ }
189
194
last [ dot ] = object [ key ] ;
190
195
} else {
191
- last [ dot ] = last [ dot ] || { } ;
196
+ last [ dot ] = last [ dot ] || ( / ^ \d + $ / . test ( dots [ j + 1 ] ) ? [ ] : { } ) ;
192
197
}
193
198
199
+ parent = last ;
194
200
last = last [ dot ] ;
195
201
}
196
202
}
You can’t perform that action at this time.
0 commit comments