Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Body defaults to {} even if type fn returns false #146

Closed
danpaz opened this issue Dec 16, 2015 · 5 comments
Closed

Body defaults to {} even if type fn returns false #146

danpaz opened this issue Dec 16, 2015 · 5 comments
Assignees

Comments

@danpaz
Copy link

danpaz commented Dec 16, 2015

What is the expected behavior if the content type of the request doesn't match the type option in the text parser? I think my expectation is that the parser should do nothing; req.body should not be populated and should remain undefined.

However, based on this test and this code it looks like req.body gets set to {} by default.

This caused a bug in my application because further down the middleware chain I check for the truthiness of req.body, and empty object happens to be truthy.

!!{} // true
@d6u
Copy link

d6u commented Dec 16, 2015

I think the expected behavior is that if bodyparser is not parsing anything, nothing should be touched.

@dougwilson
Copy link
Contributor

You need to use the 2.x branch until it is released. This issue has already been fixed, but 2.x is not yet complete.

npm install expressjs/body-parser#2.x

Be aware that the current 2.x line does not yet have all the features of 1.x, as we are working on it.

@dougwilson dougwilson self-assigned this Dec 16, 2015
@dougwilson
Copy link
Contributor

You can find a previous answer I gave at #128 (comment) if it helps explain more.

I closed this issue because there isn't work to do to fix it, as the work has already been done, just not yet released due to some edge case bugs still being addressed.

@danpaz
Copy link
Author

danpaz commented Dec 16, 2015

Sounds good, thank you!

@dougwilson
Copy link
Contributor

I'm going to work tonight on getting a proper alpha published to npm as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants