tj / node-querystring

querystring parser for node and the browser - supporting nesting (used by Express, Connect, etc)
MIT License
455 stars 66 forks source link

parse: Empty Array fields are removed #39

Open brianreavis opened 12 years ago

brianreavis commented 12 years ago

Scenario:

 photo_id[]=1
 photo_caption[]=
 photo_id[]=2
 photo_caption[]=Hello

qs.parse returns:

{
     photo_id: ['1', '2'],
     photo_caption: ['Hello']
}

The correct version should be:

{
     photo_id: ['1', '2'],
     photo_caption: ['', 'Hello']
}

Otherwise, it's impossible to maintain associations between the ordered fields.

tj commented 12 years ago

+1 from me though you could key them:

> require('qs').parse('photo[foo][id]=1&photo[foo][caption]=hey')
{ photo: { foo: { id: '1', caption: 'hey' } } }
daguej commented 10 years ago

This is still an issue, however you could use the built-in querystring module as a workaround.