request.query.hasOwnProperty causes "hasOwnProperty is not a function" error #3280

Closed
jeremiahlee opened this Issue Aug 3, 2016 · 2 comments

Comments

Projects
None yet
3 participants

I'm having a new issue with node v6.3.1 and hapi v14.1.0.

A handler function with request.query.hasOwnProperty('whatever') will result in a "request.query.hasOwnProperty is not a function" error.

Changing to Object.prototype.hasOwnProperty.call(request.query, 'whatever') works.

typeof request is 'object', so I'm not sure why this method is missing or why calling it from Object works.

jasnell commented Aug 3, 2016

This is expected. nodejs/node#6289 modified the query object returned by the querystring module such that it uses a null prototype, and therefore does not inherit the base properties and methods of ordinary Object instances. This was done intentionally to address some bugs that are detailed in the PR. Your workaround is the proper alternative.

Thanks @jasnell. Closing issue.

jeremiahlee closed this Aug 3, 2016

hueniverse added the non-issue label Aug 3, 2016

mauromereu referenced this issue in silas/hapi-fields Sep 22, 2016

Closed

request.query.hasOwnProperty is not a function #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment