Skip to content

Body parser, req.body is instantiated on null prototype #171

@Maximization

Description

@Maximization

In my project I'm using multer together with Joi to validate incoming body requests. I've noticed this was giving me an error of undefined while other non multipart type requests going through body-parser worked just fine. I managed to track the error to the fact that Joi uses hasOwnProperty on req.body while multer instantiates req.body on null as Object.create(null), this can be found here. Therefore none of the global object functions are available to use on req.body.

It might be nice to instantiate req.body as an object literal {} or Object.create(Object.prototype) to have those methods available on the parsed body for further use down the middleware chain. Body parser already does this as you can see here.

Let me know what you think and if you agree. I can submit a quick PR if you want to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions