Skip to content

Comma-delimited array parsing fails when individual items contain commas #311

@lionel-rowe

Description

@lionel-rowe

Comma-delimited array parsing fails when running something like this:

Qs.parse('things=a%2C%20b,c%2C%20d', {
  comma: true
});

Expected: { things: ['a, b', 'c, d'] }
Actual: { things: ['a', ' b', 'c', ' d'] }

Per my understanding of RFC 3986, a percent-encoded comma should not be treated the same as a comma literal. Comma literal is a reserved character used for delimiting parameters and parameter values, but a percent-encoded comma is not.

My use case needs to deal with arbitrary user input within values, potentially including commas.

I guess this can be fixed with a custom decoder function, but it seems like something that should work by default when comma is true.

As my use case is otherwise fairly simple and I don't need lots of custom features, I figured I'd just roll my own query string parser/serializer. I'm linking to this strictly for reference and wouldn't recommend anyone to use it in production in its current state - it probably diverges from the RFC in a million other ways and fails for lots of edge cases that aren't relevant to my specific use case.

Related: #237 (but that deals with stringify, whereas this is about parse).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions