Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix defaulting to extended url parsing #536

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var depth = extended ? (options.depth !== undefined ? options.depth : 32) : 0
var depth = extended ? (typeof 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
Loading