Skip to content

docs: fix depth error description - #776

Merged
UlisesGascon merged 1 commit into
expressjs:masterfrom
johnnyhuirilef:docs/urlencoded-depth-error
Oct 21, 2026
Merged

UlisesGascon merged 1 commit into
expressjs:masterfrom
johnnyhuirilef:docs/urlencoded-depth-error

Conversation

@johnnyhuirilef

Copy link
Copy Markdown
Contributor

Hi! 🙂 The README says that the "input exceeded the depth" error is not thrown when depth is 32, the default. It is thrown. urlencoded always passes strictDepth: true to qs, so with the default configuration an input with 33 levels of nesting gets a 400.

const http = require('http')
const bodyParser = require('body-parser')
const parse = bodyParser.urlencoded({ extended: true })

const server = http.createServer((req, res) => {
  parse(req, res, (err) => res.end(err ? `${err.status} ${err.message}` : '200'))
}).listen(0, async () => {
  for (const n of [32, 33]) {
    const res = await fetch(`http://localhost:${server.address().port}`, {
      method: 'POST',
      headers: { 'content-type': 'application/x-www-form-urlencoded' },
      body: 'a' + '[a]'.repeat(n) + '=1'
    })
    console.log(`${n} levels: ${await res.text()}`)
  }
  server.close()
})

Output on 2.3.0 and on 1.20.8 (Node 24.21.0):

32 levels: 200
33 levels: 400 The input exceeded the depth

The existing tests in test/urlencoded.js ('when default value') already expect this: 32 levels pass, 33 return 400. This change replaces the last sentence of that section with the real behavior.

The 1.x branch has the same sentence. Happy to open a PR there too, or to change the wording 🙌

The README said that the error is not thrown when depth is 32, the default. The parser always uses strictDepth, so with the default value an input with 33 or more levels of nesting gets a 400 error.
@krzysdz krzysdz added the docs label Oct 21, 2026
@krzysdz

krzysdz commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

I have no idea what this was supposed to mean. Maybe @UlisesGascon changed his mind while writing the code, but forgot to update the docs. afd0f39

The test that checks if the error is thrown when the default depth limit is used:

it('should not parse beyond the specified depth', function (done) {
let deepObject = 'a'
for (let i = 0; i < 33; i++) {
deepObject += '[p]'
}
deepObject += '=value'
request(this.server)
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send(deepObject)
.expect(400, '[querystring.parse.rangeError] The input exceeded the depth', done)
})

@UlisesGascon UlisesGascon self-assigned this Oct 21, 2026
@UlisesGascon
UlisesGascon merged commit 73713f7 into expressjs:master Oct 21, 2026
5 checks passed
@UlisesGascon UlisesGascon mentioned this pull request Oct 21, 2026
UlisesGascon pushed a commit that referenced this pull request Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants