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', () => {
245245 } ) ;
246246
247247 test ( 'assembleQueryData' , ( ) => {
248- const result = utils . assembleQueryData ( {
248+ const result1 = utils . assembleQueryData ( {
249249 'a' : 'b' ,
250250 'b.a' : 'foo' ,
251251 'b.b.a' : 'foo' ,
@@ -258,7 +258,21 @@ describe('VFS Utils', () => {
258258 'e' : '1'
259259 } ) ;
260260
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 ( {
262276 a : 'b' ,
263277 b : {
264278 a : 'foo' ,
@@ -274,5 +288,23 @@ describe('VFS Utils', () => {
274288 d : 'true' ,
275289 e : '1'
276290 } ) ;
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+ } ) ;
277309 } ) ;
278310} ) ;
Original file line number Diff line number Diff line change @@ -183,14 +183,20 @@ const assembleQueryData = (object) => {
183183 const dots = key . split ( '.' ) ;
184184
185185 let last = assembled ;
186+ let parent = null ;
186187 for ( let j = 0 ; j < dots . length ; j ++ ) {
187188 const dot = dots [ j ] ;
188189 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+ }
189194 last [ dot ] = object [ key ] ;
190195 } else {
191- last [ dot ] = last [ dot ] || { } ;
196+ last [ dot ] = last [ dot ] || ( / ^ \d + $ / . test ( dots [ j + 1 ] ) ? [ ] : { } ) ;
192197 }
193198
199+ parent = last ;
194200 last = last [ dot ] ;
195201 }
196202 }
You can’t perform that action at this time.
0 commit comments