Skip to content

Array with single value is stringified as string when using arrayFormat 'comma' #403

Open
@iyedb

Description

@iyedb

queryString.stringify({values: ['foo']}, {arrayFormat: 'comma'} )
=> values='foo'
when parsing back with arrayFormat 'comma', the result is {values: 'foo'}

here is a test to reproduce the bug (the test fails):

it("parses array with a single value bug", () => {
    const q = queryString.stringify(
      { values: ["foo"] },
      { arrayFormat: "comma" },
    );
    console.log(q);
    const parsed = queryString.parse(q, { arrayFormat: "comma" });
    console.log(parsed);
    expect(parsed).toEqual({
      values: ["foo"],
    });
  });

The information that values is an array is lost when stringifying.
Workaround: use `arrayFormat: "bracket-separator"

This bug makes the "comma" format unusable.

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