Skip to content
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
13 changes: 6 additions & 7 deletions lib/types/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ var JSON_SYNTAX_REGEXP = /#+/g
*/

function json (options) {
var opts = options || {}
var { inflate, limit, verify, shouldParse } = normalizeOptions(opts, 'application/json')
var { inflate, limit, verify, shouldParse } = normalizeOptions(options, 'application/json')

var reviver = opts.reviver
var strict = opts.strict !== false
var reviver = options?.reviver
var strict = options?.strict !== false

function parse (body) {
if (body.length === 0) {
Expand Down Expand Up @@ -125,9 +124,9 @@ function json (options) {
// read
read(req, res, next, parse, debug, {
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify
inflate,
limit,
verify
})
}
}
Expand Down
9 changes: 4 additions & 5 deletions lib/types/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ module.exports = raw
*/

function raw (options) {
var opts = options || {}
var { inflate, limit, verify, shouldParse } = normalizeOptions(opts, 'application/octet-stream')
var { inflate, limit, verify, shouldParse } = normalizeOptions(options, 'application/octet-stream')

function parse (buf) {
return buf
Expand Down Expand Up @@ -68,9 +67,9 @@ function raw (options) {
// read
read(req, res, next, parse, debug, {
encoding: null,
inflate: inflate,
limit: limit,
verify: verify
inflate,
limit,
verify
})
}
}
11 changes: 5 additions & 6 deletions lib/types/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ module.exports = text
*/

function text (options) {
var opts = options || {}
var { inflate, limit, verify, shouldParse } = normalizeOptions(opts, 'text/plain')
var { inflate, limit, verify, shouldParse } = normalizeOptions(options, 'text/plain')

var defaultCharset = opts.defaultCharset || 'utf-8'
var defaultCharset = options?.defaultCharset || 'utf-8'

function parse (buf) {
return buf
Expand Down Expand Up @@ -73,9 +72,9 @@ function text (options) {
// read
read(req, res, next, parse, debug, {
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify
inflate,
limit,
verify
})
}
}
33 changes: 13 additions & 20 deletions lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,15 @@ module.exports = urlencoded
*/

function urlencoded (options) {
var opts = options || {}
var { inflate, limit, verify, shouldParse } = normalizeOptions(opts, 'application/x-www-form-urlencoded')
var { inflate, limit, verify, shouldParse } = normalizeOptions(options, 'application/x-www-form-urlencoded')

var extended = Boolean(opts.extended)
var charsetSentinel = opts.charsetSentinel
var interpretNumericEntities = opts.interpretNumericEntities

var defaultCharset = opts.defaultCharset || 'utf-8'
var defaultCharset = options?.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')
}

// create the appropriate query parser
var queryparse = createQueryParser(opts, extended)
var queryparse = createQueryParser(options)

function parse (body, encoding) {
return body.length
Expand Down Expand Up @@ -96,13 +91,10 @@ function urlencoded (options) {

// read
read(req, res, next, parse, debug, {
debug: debug,
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify,
charsetSentinel: charsetSentinel,
interpretNumericEntities: interpretNumericEntities
inflate,
limit,
verify
})
}
}
Expand All @@ -113,13 +105,14 @@ function urlencoded (options) {
* @param {object} options
*/

function createQueryParser (options, extended) {
var parameterLimit = options.parameterLimit !== undefined
? options.parameterLimit
function createQueryParser (options) {
var extended = Boolean(options?.extended)
var parameterLimit = options?.parameterLimit !== undefined
? options?.parameterLimit
: 1000
var charsetSentinel = options.charsetSentinel
var interpretNumericEntities = options.interpretNumericEntities
var depth = extended ? (options.depth !== undefined ? options.depth : 32) : 0
var charsetSentinel = options?.charsetSentinel
var interpretNumericEntities = options?.interpretNumericEntities
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')
Expand Down