Skip to content

Commit

Permalink
chore: linter (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Sep 9, 2024
1 parent b2695c4 commit 39744cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
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

0 comments on commit 39744cf

Please sign in to comment.