Skip to content

Commit 744a350

Browse files
authored
Fix defaulting to extended url parsing (#536)
1 parent 9e06a79 commit 744a350

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

lib/types/urlencoded.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ function urlencoded (options) {
5252
throw new TypeError('option verify must be function')
5353
}
5454

55-
var depth = typeof opts.depth !== 'number'
56-
? Number(opts.depth || 32)
57-
: opts.depth
58-
5955
var defaultCharset = opts.defaultCharset || 'utf-8'
6056
if (defaultCharset !== 'utf-8' && defaultCharset !== 'iso-8859-1') {
6157
throw new TypeError('option defaultCharset must be either utf-8 or iso-8859-1')
@@ -121,8 +117,7 @@ function urlencoded (options) {
121117
limit: limit,
122118
verify: verify,
123119
charsetSentinel: charsetSentinel,
124-
interpretNumericEntities: interpretNumericEntities,
125-
depth: depth
120+
interpretNumericEntities: interpretNumericEntities
126121
})
127122
}
128123
}
@@ -139,10 +134,7 @@ function createQueryParser (options, extended) {
139134
: 1000
140135
var charsetSentinel = options.charsetSentinel
141136
var interpretNumericEntities = options.interpretNumericEntities
142-
143-
var depth = typeof options.depth !== 'number'
144-
? Number(options.depth || 32)
145-
: options.depth
137+
var depth = extended ? (options.depth !== undefined ? options.depth : 32) : 0
146138

147139
if (isNaN(parameterLimit) || parameterLimit < 1) {
148140
throw new TypeError('option parameterLimit must be a positive number')

test/urlencoded.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('bodyParser.urlencoded()', function () {
166166
.post('/')
167167
.set('Content-Type', 'application/x-www-form-urlencoded')
168168
.send('user[name][first]=Tobi')
169-
.expect(200, '{"user":{"name":{"first":"Tobi"}}}', done)
169+
.expect(200, '{"user[name][first]":"Tobi"}', done)
170170
})
171171

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

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

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

326326
describe('when default value', function () {
327327
before(function () {
328-
this.server = createServer({ })
328+
this.server = createServer({ extended: true })
329329
})
330330

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy