Skip to content

Default arrayFormat causes arrays of length 1 to be serialised the same as a string #206

Open
@hedgepigdaniel

Description

@hedgepigdaniel

The default arrayFormat value of none is problematic because arrays of length 1 are serialised to the same format as if the value was the string contained within the array.

For example:

qs.parse(qs.stringify({a: 'val'})); // {a: 'val'}
qs.parse(qs.stringify({a: ['val']})); // {a: 'val'} WRONG/UNEXPECTED
qs.parse(qs.stringify({a: ['val', 'val2']})); // {a: ['val', 'val2']}

Perhaps the default arrayFormat should be changed to bracket or index, which do not have this problem. The none option would make more sense IMO if it refused to stringify an array when stringifying, and ignored/crash for duplicate keys when parsing. I don't see how the comma option can be made to handle arrays consistently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions