Skip to content

qs.parse (with allowDots) provided with the same key object and strings gives varying results #122

@MadManMathew

Description

@MadManMathew

When using qs to parse our url for advanced queries I came across an issue where we get varying/expected or desired results when we provide the same parent key one as string and the other intended to be an object. The example will clear things up.

qs.parse('address=123+main+st&address.city=vancouver' ,{allowDots:true});
  //  returns  {address: [ 123+main+stf', { city: 'vancouver' } ] }

which is as expected, however if we reverse the order

qs.parse('address.city=vancouver&address=123+main+st' ,{allowDots:true});
  //  returns  {address: { city: 'vancouver',  '123+main+st':true }  }

order shouldn't matter. Once again

qs.parse('address.city=vancouver&address=123+main+st&address=321+baltic+ave' ,{allowDots:true});
  //  returns  {address: { city: 'vancouver',  '0': '123+main+st', '1':'321+baltic+ave}  }

Solution

keep the results consistent and use the object array notation in each of the cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions