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

function json (options) {
var normalizedOptions = normalizeOptions(options, 'application/json')
const normalizedOptions = normalizeOptions(options, 'application/json')

var reviver = options?.reviver
var strict = options?.strict !== false
Expand Down Expand Up @@ -80,13 +80,14 @@ function json (options) {
}
}

return function jsonParser (req, res, next) {
read(req, res, next, parse, debug, {
...normalizedOptions,
const readOptions = {
...normalizedOptions,
// assert charset per RFC 7159 sec 8.1
isValidCharset: (charset) => charset.slice(0, 4) === 'utf-'
}

// assert charset per RFC 7159 sec 8.1
isValidCharset: (charset) => charset.slice(0, 4) === 'utf-'
})
return function jsonParser (req, res, next) {
read(req, res, next, parse, debug, readOptions)
}
}

Expand Down
15 changes: 8 additions & 7 deletions lib/types/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ module.exports = raw
*/

function raw (options) {
var normalizedOptions = normalizeOptions(options, 'application/octet-stream')
const normalizedOptions = normalizeOptions(options, 'application/octet-stream')

return function rawParser (req, res, next) {
read(req, res, next, passthrough, debug, {
...normalizedOptions,
const readOptions = {
...normalizedOptions,
// Skip charset validation and parse the body as is
skipCharset: true
}

// Skip charset validation and parse the body as is
skipCharset: true
})
return function rawParser (req, res, next) {
read(req, res, next, passthrough, debug, readOptions)
}
}
2 changes: 1 addition & 1 deletion lib/types/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = text
*/

function text (options) {
var normalizedOptions = normalizeOptions(options, 'text/plain')
const normalizedOptions = normalizeOptions(options, 'text/plain')

return function textParser (req, res, next) {
read(req, res, next, passthrough, debug, normalizedOptions)
Expand Down
15 changes: 8 additions & 7 deletions lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = urlencoded
*/

function urlencoded (options) {
var normalizedOptions = normalizeOptions(options, 'application/x-www-form-urlencoded')
const normalizedOptions = normalizeOptions(options, 'application/x-www-form-urlencoded')

if (normalizedOptions.defaultCharset !== 'utf-8' && normalizedOptions.defaultCharset !== 'iso-8859-1') {
throw new TypeError('option defaultCharset must be either utf-8 or iso-8859-1')
Expand All @@ -48,13 +48,14 @@ function urlencoded (options) {
: {}
}

return function urlencodedParser (req, res, next) {
read(req, res, next, parse, debug, {
...normalizedOptions,
const readOptions = {
...normalizedOptions,
// assert charset
isValidCharset: (charset) => charset === 'utf-8' || charset === 'iso-8859-1'
}

// assert charset
isValidCharset: (charset) => charset === 'utf-8' || charset === 'iso-8859-1'
})
return function urlencodedParser (req, res, next) {
read(req, res, next, parse, debug, readOptions)
}
}

Expand Down