Skip to content

Commit

Permalink
Fix defaulting to extended url parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Sep 10, 2024
1 parent 9e06a79 commit 675b2d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
12 changes: 2 additions & 10 deletions lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ function urlencoded (options) {
throw new TypeError('option verify must be function')
}

var depth = typeof opts.depth !== 'number'
? Number(opts.depth || 32)
: opts.depth

var defaultCharset = opts.defaultCharset || 'utf-8'
if (defaultCharset !== 'utf-8' && defaultCharset !== 'iso-8859-1') {
throw new TypeError('option defaultCharset must be either utf-8 or iso-8859-1')
Expand Down Expand Up @@ -121,8 +117,7 @@ function urlencoded (options) {
limit: limit,
verify: verify,
charsetSentinel: charsetSentinel,
interpretNumericEntities: interpretNumericEntities,
depth: depth
interpretNumericEntities: interpretNumericEntities
})
}
}
Expand All @@ -139,10 +134,7 @@ function createQueryParser (options, extended) {
: 1000
var charsetSentinel = options.charsetSentinel
var interpretNumericEntities = options.interpretNumericEntities

var depth = typeof options.depth !== 'number'
? Number(options.depth || 32)
: options.depth
var depth = extended ? (options.depth !== undefined ? options.depth : 32) : 0

if (isNaN(parameterLimit) || parameterLimit < 1) {
throw new TypeError('option parameterLimit must be a positive number')
Expand Down
8 changes: 4 additions & 4 deletions test/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('bodyParser.urlencoded()', function () {
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send('user[name][first]=Tobi')
.expect(200, '{"user":{"name":{"first":"Tobi"}}}', done)
.expect(200, '{"user[name][first]":"Tobi"}', done)
})

describe('with extended option', function () {
Expand All @@ -180,7 +180,7 @@ describe('bodyParser.urlencoded()', function () {
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send('user[name][first]=Tobi')
.expect(200, '{"user":{"name":{"first":"Tobi"}}}', done)
.expect(200, '{"user[name][first]":"Tobi"}', done)
})

it('should parse multiple key instances', function (done) {
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('bodyParser.urlencoded()', function () {

describe('with depth option', function () {
describe('when custom value set', function () {
it('should reject non possitive numbers', function () {
it('should reject non positive numbers', function () {
assert.throws(createServer.bind(null, { extended: true, depth: -1 }),
/TypeError: option depth must be a zero or a positive number/)
assert.throws(createServer.bind(null, { extended: true, depth: NaN }),
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('bodyParser.urlencoded()', function () {

describe('when default value', function () {
before(function () {
this.server = createServer({ })
this.server = createServer({ extended: true })
})

it('should parse deeply nested objects', function (done) {
Expand Down

0 comments on commit 675b2d4

Please sign in to comment.