ljharb/qs

Cannot parse array of objects using arrayFormat = 'brackets'

Open

#215 aperta il 13 giu 2017

Vedi su GitHub
 (13 commenti) (11 reazioni) (0 assegnatari)JavaScript (744 fork)batch import
bughelp wantedparse

Metriche repository

Star
 (8015 star)
Metriche merge PR
 (Merge medio 6g 22h) (2 PR mergiate in 30 g)

Descrizione

The README states:

You can also create arrays of objects:

var arraysOfObjects = qs.parse('a[][b]=c');
assert.deepEqual(arraysOfObjects, { a: [{ b: 'c' }] });

However when you try to parse an array with 2 objects, an object with 2 keys is created instead:

var arraysOfObjects = qs.parse('a[][b]=c&a[][d]=e');
assert.deepEqual(arraysOfObjects, { a: [{ b: 'c' , d: 'e'}] });

This also happens with arrayFormat = 'repeat'.

If arrays without indices cannot be supported, may the allowDots option could affect arrays instead: (a.0.b=c&a.1.d=e)

Guida contributor