Skip to content
This repository has been archived by the owner on Jul 23, 2018. It is now read-only.

Fix buildRequestData when req.body is a plain object #72

Merged
merged 1 commit into from
Feb 18, 2016

Conversation

jondeandres
Copy link
Contributor

Some libraries, like multer create req.body in this way:

req.body = Object.create(null)

In that case we cannot call req.body.hasOwnProperty(). In this PR we check that req.body has hasOwnProperty function or the req.body.constructor is undefined, so it is a plain Object and we
can be sure that the keys are part of the body

@jondeandres jondeandres force-pushed the fix-build-request-data branch 2 times, most recently from a591716 to 4a6805e Compare February 16, 2016 18:38
for (k in req.body) {
if (req.body.hasOwnProperty(k)) {
var hasOwnProperty = typeof req.body.hasOwnProperty === 'function' && req.body.hasOwnProperty(k);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Extra ws before req.body.hasOwnProperty(k)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@coryvirok
Copy link
Contributor

Great. LGTM

@jondeandres jondeandres force-pushed the fix-build-request-data branch from 4a6805e to 4cf5104 Compare February 18, 2016 17:20
Some libraries, like [multer](https://github.com/expressjs/multer)
create `req.body` in this way:

`req.body = Object.create(null)`

In that case we cannot call `req.body.hasOwnProperty()`. In this PR we
check that `req.body` has `hasOwnProperty` function or the
`req.body.constructor` is undefined, so it is a plain `Object` and we
can be sure that the keys are part of the body

Fixes #68
@jondeandres jondeandres force-pushed the fix-build-request-data branch from 4cf5104 to df60735 Compare February 18, 2016 17:20
jondeandres added a commit that referenced this pull request Feb 18, 2016
Fix buildRequestData when req.body is a plain object
@jondeandres jondeandres merged commit 4ffd7ed into master Feb 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants