Skip to content

[email protected] update changes default body-parser behaviour #687

Closed

Description

@efekrskl

Passing arrayLimit as 0 to [email protected] parses arrays as objects with indexes instead of arrays (lib/types/urlencoded.js:99). Since extended is false by default, our default behaviour has changed.

There's also a failing test

  1) bodyParser.urlencoded()
       with extended option
         when false
           should parse multiple key instances:
     Error: expected '{"user":["Tobi","Loki"]}' response body, got '{"user":{"0":"Tobi","1":"Loki"}}'

Environment information

Version: 2.2.1

Platform:

Node.js version:

Any other relevant information:

What steps will reproduce the bug?

npm run test

Activity

  1. added theissue type on Jan 3, 2026
  2. krzysdz commented on Jan 3, 2026

    @krzysdz
    Contributor

    According to ljharb/qs#537 (comment) this should have never worked in the first place. body-parser 2.0.0 changed the "simple" query parser to use qs instead of querystring (PR #387), but the behaviour should be the same (see discussion in #326).

    I think it could be solved by increasing arrayLimit, because it looks like with current options sparse arrays are not allowed anyway.

    @ljharb could you look into this?

  3. ljharb commented on Jan 4, 2026

    @ljharb
    Contributor

    Indeed, expecting arrays over 20 items should have never worked in the first place. Setting it to zero means you should never expect an array.

  4. jonchurch commented on Jan 5, 2026

    @jonchurch
    Member

    simple mode depends on parsing as many array items as options?.parameterLimit (default 1000), so my fix is to set arrayLimit to our parameter count 474ccd3

    I think we took a dep on the buggy behavior in qs itself while prototyping a backwards compatible migration from node:querystring, somewhere around #326 (comment)

    it was committed in #387

    the bug doesnt bite us because we just so happen to limit the input we parse another way

  5. jonchurch commented on Jan 5, 2026

    @jonchurch
    Member

    Pr to body-parser 2.x line to fix this #689

    To be released in #691

  6. self-assigned this
    on Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions