Skip to content

Commit

Permalink
Merge tag '1.20.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 22, 2023
2 parents 3f5e93e + ee91374 commit 2fd44ac
Show file tree
Hide file tree
Showing 13 changed files with 699 additions and 187 deletions.
37 changes: 26 additions & 11 deletions .github/workflows/ci.yml
Expand Up @@ -29,6 +29,8 @@ jobs:
- Node.js 15.x
- Node.js 16.x
- Node.js 17.x
- Node.js 18.x
- Node.js 19.x

include:
- name: Node.js 0.10
Expand Down Expand Up @@ -85,24 +87,32 @@ jobs:

- name: Node.js 12.x
node-version: "12.22"
npm-i: mocha@9.2.2

- name: Node.js 13.x
node-version: "13.14"
npm-i: mocha@9.2.2

- name: Node.js 14.x
node-version: "14.19"
node-version: "14.21"

- name: Node.js 15.x
node-version: "15.14"

- name: Node.js 16.x
node-version: "16.14"
node-version: "16.19"

- name: Node.js 17.x
node-version: "17.5"
node-version: "17.9"

- name: Node.js 18.x
node-version: "18.14"

- name: Node.js 19.x
node-version: "19.7"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install Node.js ${{ matrix.node-version }}
shell: bash -eo pipefail -l {0}
Expand All @@ -111,7 +121,12 @@ jobs:
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"
- name: Configure npm
run: npm config set shrinkwrap false
run: |
if [[ "$(npm config get package-lock)" == "true" ]]; then
npm config set package-lock false
else
npm config set shrinkwrap false
fi
- name: Install npm module(s) ${{ matrix.npm-i }}
run: npm install --save-dev ${{ matrix.npm-i }}
Expand All @@ -121,8 +136,8 @@ jobs:
shell: bash
run: |
# eslint for linting
# - remove on Node.js < 10
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then
# - remove on Node.js < 12
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 12 ]]; then
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \
grep -E '^eslint(-|$)' | \
sort -r | \
Expand All @@ -139,7 +154,7 @@ jobs:
echo "node@$(node -v)"
echo "npm@$(npm -v)"
npm -s ls ||:
(npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }'
(npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT"
- name: Run tests
shell: bash
Expand All @@ -165,7 +180,7 @@ jobs:
fi
- name: Upload code coverage
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: steps.list_env.outputs.nyc != ''
with:
name: coverage
Expand All @@ -176,14 +191,14 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install lcov
shell: bash
run: sudo apt-get -y install lcov

- name: Collect coverage reports
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: coverage
path: ./coverage
Expand Down
34 changes: 33 additions & 1 deletion HISTORY.md
@@ -1,7 +1,7 @@
2.x
===

This incorporates all changes after 1.19.1 up to 1.19.2.
This incorporates all changes after 1.19.1 up to 1.20.2.

2.0.0-beta.1 / 2021-12-17
=========================
Expand All @@ -11,6 +11,38 @@ This incorporates all changes after 1.19.1 up to 1.19.2.
* `urlencoded` parser now defaults `extended` to `false`
* Use `on-finished` to determine when body read

1.20.2 / 2023-02-21
===================

* Fix strict json error message on Node.js 19+
* deps: content-type@~1.0.5
- perf: skip value escaping when unnecessary
* deps: raw-body@2.5.2

1.20.1 / 2022-10-06
===================

* deps: qs@6.11.0
* perf: remove unnecessary object clone

1.20.0 / 2022-04-02
===================

* Fix error message for json parse whitespace in `strict`
* Fix internal error when inflated body exceeds limit
* Prevent loss of async hooks context
* Prevent hanging when request already read
* deps: depd@2.0.0
- Replace internal `eval` usage with `Function` constructor
- Use instance methods on `process` to check for listeners
* deps: http-errors@2.0.0
- deps: depd@2.0.0
- deps: statuses@2.0.1
* deps: on-finished@2.4.1
* deps: qs@6.10.3
* deps: raw-body@2.5.1
- deps: http-errors@2.0.0

1.19.2 / 2022-02-15
===================

Expand Down
29 changes: 19 additions & 10 deletions README.md
@@ -1,8 +1,8 @@
# body-parser

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][github-actions-ci-image]][github-actions-ci-url]
[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Build Status][ci-image]][ci-url]
[![Test Coverage][coveralls-image]][coveralls-url]

Node.js body parsing middleware.
Expand Down Expand Up @@ -338,6 +338,14 @@ to this middleware. This module operates directly on bytes only and you cannot
call `req.setEncoding` when using this module. The `status` property is set to
`500` and the `type` property is set to `'stream.encoding.set'`.

### stream is not readable

This error will occur when the request is no longer readable when this middleware
attempts to read it. This typically means something other than a middleware from
this module read the request body already and the middleware was also configured to
read the same request. The `status` property is set to `500` and the `type`
property is set to `'stream.not.readable'`.

### too many parameters

This error will occur when the content of the request exceeds the configured
Expand Down Expand Up @@ -444,11 +452,12 @@ app.use(bodyParser.text({ type: 'text/html' }))

[MIT](LICENSE)

[npm-image]: https://img.shields.io/npm/v/body-parser.svg
[npm-url]: https://npmjs.org/package/body-parser
[coveralls-image]: https://img.shields.io/coveralls/expressjs/body-parser/master.svg
[ci-image]: https://badgen.net/github/checks/expressjs/body-parser/master?label=ci
[ci-url]: https://github.com/expressjs/body-parser/actions/workflows/ci.yml
[coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/body-parser/master
[coveralls-url]: https://coveralls.io/r/expressjs/body-parser?branch=master
[downloads-image]: https://img.shields.io/npm/dm/body-parser.svg
[downloads-url]: https://npmjs.org/package/body-parser
[github-actions-ci-image]: https://img.shields.io/github/workflow/status/expressjs/body-parser/ci/master?label=ci
[github-actions-ci-url]: https://github.com/expressjs/body-parser?query=workflow%3Aci
[node-version-image]: https://badgen.net/npm/node/body-parser
[node-version-url]: https://nodejs.org/en/download
[npm-downloads-image]: https://badgen.net/npm/dm/body-parser
[npm-url]: https://npmjs.org/package/body-parser
[npm-version-image]: https://badgen.net/npm/v/body-parser
25 changes: 25 additions & 0 deletions SECURITY.md
@@ -0,0 +1,25 @@
# Security Policies and Procedures

## Reporting a Bug

The Express team and community take all security bugs seriously. Thank you
for improving the security of Express. We appreciate your efforts and
responsible disclosure and will make every effort to acknowledge your
contributions.

Report security bugs by emailing the current owner(s) of `body-parser`. This
information can be found in the npm registry using the command
`npm owner ls body-parser`.
If unsure or unable to get the information from the above, open an issue
in the [project issue tracker](https://github.com/expressjs/body-parser/issues)
asking for the current contact information.

To ensure the timely response to your report, please ensure that the entirety
of the report is contained within the email body and not solely behind a web
link or an attachment.

At least one owner will acknowledge your email within 48 hours, and will send a
more detailed response within 48 hours indicating the next steps in handling
your report. After the initial reply to your report, the owners will
endeavor to keep you informed of the progress towards a fix and full
announcement, and may ask for additional information or guidance.
17 changes: 8 additions & 9 deletions index.js
Expand Up @@ -91,16 +91,15 @@ Object.defineProperty(exports, 'urlencoded', {
*/

function bodyParser (options) {
var opts = {}

// exclude type option
if (options) {
for (var prop in options) {
if (prop !== 'type') {
opts[prop] = options[prop]
}
// use default type for parsers
var opts = Object.create(options || null, {
type: {
configurable: true,
enumerable: true,
value: undefined,
writable: true
}
}
})

var _urlencoded = exports.urlencoded(opts)
var _json = exports.json(opts)
Expand Down
28 changes: 26 additions & 2 deletions lib/read.js
Expand Up @@ -12,9 +12,11 @@
*/

var createError = require('http-errors')
var destroy = require('destroy')
var getBody = require('raw-body')
var iconv = require('iconv-lite')
var onFinished = require('on-finished')
var unpipe = require('unpipe')
var zlib = require('zlib')

/**
Expand Down Expand Up @@ -86,9 +88,14 @@ function read (req, res, next, parse, debug, options) {
_error = createError(400, error)
}

// unpipe from stream and destroy
if (stream !== req) {
unpipe(req)
destroy(stream, true)
}

// read off entire request
stream.resume()
onFinished(req, function onfinished () {
dump(req, function onfinished () {
next(createError(400, _error))
})
return
Expand Down Expand Up @@ -176,3 +183,20 @@ function contentstream (req, debug, inflate) {

return stream
}

/**
* Dump the contents of a request.
*
* @param {object} req
* @param {function} callback
* @api private
*/

function dump (req, callback) {
if (onFinished.isFinished(req)) {
callback(null)
} else {
onFinished(req, callback)
req.resume()
}
}
27 changes: 22 additions & 5 deletions lib/types/json.js
Expand Up @@ -38,7 +38,10 @@ module.exports = json
* %x0D ) ; Carriage return
*/

var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*(.)/ // eslint-disable-line no-control-regex
var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/ // eslint-disable-line no-control-regex

var JSON_SYNTAX_CHAR = '#'
var JSON_SYNTAX_REGEXP = /#+/g

/**
* Create a middleware to parse JSON bodies.
Expand Down Expand Up @@ -125,7 +128,7 @@ function json (options) {

// assert charset per RFC 7159 sec 8.1
var charset = getCharset(req) || 'utf-8'
if (charset.substr(0, 4) !== 'utf-') {
if (charset.slice(0, 4) !== 'utf-') {
debug('invalid charset')
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
charset: charset,
Expand Down Expand Up @@ -155,13 +158,23 @@ function json (options) {

function createStrictSyntaxError (str, char) {
var index = str.indexOf(char)
var partial = str.substring(0, index) + '#'
var partial = ''

if (index !== -1) {
partial = str.substring(0, index) + JSON_SYNTAX_CHAR

for (var i = index + 1; i < str.length; i++) {
partial += JSON_SYNTAX_CHAR
}
}

try {
JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
} catch (e) {
return normalizeJsonSyntaxError(e, {
message: e.message.replace('#', char),
message: e.message.replace(JSON_SYNTAX_REGEXP, function (placeholder) {
return str.substring(index, index + placeholder.length)
}),
stack: e.stack
})
}
Expand All @@ -176,7 +189,11 @@ function createStrictSyntaxError (str, char) {
*/

function firstchar (str) {
return FIRST_CHAR_REGEXP.exec(str)[1]
var match = FIRST_CHAR_REGEXP.exec(str)

return match
? match[1]
: undefined
}

/**
Expand Down

0 comments on commit 2fd44ac

Please sign in to comment.