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

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

Closed
ghost opened this issue Aug 3, 2016 · 4 comments
Closed
Labels
non issue Issue is not a problem or requires changes

Comments

@ghost
Copy link

ghost commented Aug 3, 2016

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
Copy link

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.

@ghost
Copy link
Author

ghost commented Aug 3, 2016

Thanks @jasnell. Closing issue.

@ghost ghost closed this as completed Aug 3, 2016
@hueniverse hueniverse added the non issue Issue is not a problem or requires changes label Aug 3, 2016
klausj added a commit to IPS-LMU/IPS-EMUprot-nodeWSserver that referenced this issue Oct 16, 2017
wmfgerrit pushed a commit to wikimedia/mediawiki-extensions-AdvancedSearch that referenced this issue Feb 19, 2018
Use robust lib instead of string processing to extract query
parameters from urls.
See hapijs/hapi#3280 for explanation on
unintuitive query object prototype.

Bug: T187306
Change-Id: Idf80128af6859af8b7d568f59f7d825e3cdc5a91
ogajduse added a commit to ogajduse/dosgen that referenced this issue May 18, 2018
hapijs/hapi#3280 (comment)

Fixing:

TypeError: arguments.hasOwnProperty is not a function
    at parseAttacksArguments (/home/ogajduse/Documents/repos/dosgen/dosgen-web/routes/dosgen.js:67:23)
    at /home/ogajduse/Documents/repos/dosgen/dosgen-web/routes/dosgen.js:24:16
    at Layer.handle [as handle_request] (/home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/layer.js:82:5)
    at next (/home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/route.js:110:13)
    at Route.dispatch (/home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/route.js:91:3)
    at Layer.handle [as handle_request] (/home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/layer.js:82:5)
    at /home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/index.js:267:22
    at Function.proto.process_params (/home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/index.js:321:12)
    at next (/home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/index.js:261:10)
    at Function.proto.handle (/home/ogajduse/Documents/repos/dosgen/dosgen-web/node_modules/express/lib/router/index.js:166:3)
@Ethan-Arrowood
Copy link

Could a change to the querystring type file help with this? TypeScript should definitely be throwing an error

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
non issue Issue is not a problem or requires changes
Projects
None yet
Development

No branches or pull requests

3 participants