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

Linter #534

Merged
merged 1 commit into from
Sep 9, 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
2 changes: 1 addition & 1 deletion lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function extendedparser (options) {
throw new TypeError('option parameterLimit must be a positive number')
}

if(isNaN(depth) || depth < 0) {
if (isNaN(depth) || depth < 0) {
throw new TypeError('option depth must be a zero or a positive number')
}

Expand Down
24 changes: 9 additions & 15 deletions test/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,19 @@ describe('bodyParser.urlencoded()', function () {
})
})


describe('with depth option', function () {
describe('when custom value set', function () {

it('should reject non possitive 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 }),
/TypeError: option depth must be a zero or a positive number/)
assert.throws(createServer.bind(null, { extended: true, depth: "beep" }),
assert.throws(createServer.bind(null, { extended: true, depth: 'beep' }),
/TypeError: option depth must be a zero or a positive number/)
})


it('should parse up to the specified depth', function (done) {
this.server = createServer({ extended:true, depth: 10 })
this.server = createServer({ extended: true, depth: 10 })
request(this.server)
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
Expand All @@ -244,15 +241,14 @@ describe('bodyParser.urlencoded()', function () {
})

it('should not parse beyond the specified depth', function (done) {
this.server = createServer({ extended:true, depth: 1 })
this.server = createServer({ extended: true, depth: 1 })
request(this.server)
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send('a[b][c][d][e]=value')
.expect(400, '[querystring.parse.rangeError] The input exceeded the depth', done)
})
})


describe('when default value', function () {
before(function () {
Expand All @@ -265,7 +261,7 @@ describe('bodyParser.urlencoded()', function () {
deepObject += '[p]'
}
deepObject += '=value'

request(this.server)
.post('/')
.set('Content-Type', 'application/x-www-form-urlencoded')
Expand All @@ -281,21 +277,19 @@ describe('bodyParser.urlencoded()', function () {
})

it('should not parse beyond the specified depth', function (done) {
var deepObject = 'a';
var deepObject = 'a'
for (var i = 0; i < 33; i++) {
deepObject += '[p]';
deepObject += '[p]'
}
deepObject += '=value';
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);
});

.expect(400, '[querystring.parse.rangeError] The input exceeded the depth', done)
})
})

})

describe('with inflate option', function () {
Expand Down
Loading