Decide how invalid options are handled in the next major

Open
#775 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
28/100
Issue type
Refactor
Clarity
Needs clarification
Activity status
Active
Domain
backend

Research direction

Start by reading normalizeOptions and the json(), urlencoded(), and text() parser entry points to compare how each option is validated. Review the reported defaultCharset cases and the related change in #764. Done means a policy for invalid options has been selected, consistently implemented across parsers, and covered by tests, including case-insensitive charset handling.

Written by the indexing model from the issue text.

Description

semver-major

@Phillip9587 suggested an issue for this in #764. Measured on master (02101da) with Node 26; the Express results use Express 5.3.0.

normalizeOptions, one option at a time:

option 42 false 0 '' {}
inflate true false true true true
limit 42 throws 0 throws throws
verify throws false false false throws
defaultCharset 42 'utf-8' 'utf-8' 'utf-8' {}

type: 42 is accepted, and shouldParse() then returns false for an application/json request, so the parser quietly skips it.

defaultCharset across the parsers, for a request without a charset:

'UTF-8' 42 or {}
json() 415 unsupported charset "UTF-8" each request throws TypeError: charset.slice is not a function (500 in Express)
urlencoded() throws at construction throws at construction
text() 200 throws TypeError: encoding.toUpperCase is not a function inside the raw-body callback; Express cannot catch it and the process exits

All three treat 0, false and '' as 'utf-8'.

So one option gets three policies: checked at construction in urlencoded(), per request in json(), and not at all in text(), where a non-string value ends the process on the first request.

The question for the next major is which policy all options follow: check types at construction and throw, as limit and verify partly do, or coerce. Either way, defaultCharset needs lower-casing before the utf-8/iso-8859-1 checks, which is what #764 does.

Dominant language
JavaScript
Stars
5.5k
Forks
802
Avg merge
7h 54m
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from expressjs/body-parser

All issues in expressjs/body-parser

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.