diff --git a/lib/types/urlencoded.js b/lib/types/urlencoded.js index 273395cb..687745f8 100644 --- a/lib/types/urlencoded.js +++ b/lib/types/urlencoded.js @@ -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') @@ -121,8 +117,7 @@ function urlencoded (options) { limit: limit, verify: verify, charsetSentinel: charsetSentinel, - interpretNumericEntities: interpretNumericEntities, - depth: depth + interpretNumericEntities: interpretNumericEntities }) } } @@ -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') diff --git a/test/urlencoded.js b/test/urlencoded.js index dbf9841f..4ff9ab56 100644 --- a/test/urlencoded.js +++ b/test/urlencoded.js @@ -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 () { @@ -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) { @@ -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 }), @@ -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) {