-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ctx.query is not a plain object while ctx.params and ctx.request.body is #1472
Comments
(Not a koajs dev, but had the same issue) This is intended behavior as of node 6. Object.hasOwnProperty.call(ctx.query, 'prop_name_here'); If you can't do that (such as using a library), you can shim it instead app.use(async (ctx, next) => {
ctx.query.hasOwnProperty = function(key) {
// `this` === `ctx.query`
return Object.hasOwnProperty.call(this, key);
}
}); If that causes issues with object enumeration ( app.use(async (ctx, next) => {
function hasOwnPropertyShim(key) {
// `this` === `ctx.query`
return Object.hasOwnProperty.call(this, key);
}
Object.defineProperty(ctx.query, 'hasOwnProperty', {
value: hasOwnPropertyShim,
enumerable: false,
});
}); |
hmmm indeed. But I am running in node v10.20.1. |
Node 10 has the same behavior. Specifically
|
This behavior is by design to avoid some security problems. |
Close for now. If you have any other doubts you can continue the discussion. :) |
As screenshot shows that ctx.query has no method
hasOwnProperty
from prototypeWhich causes some package depends on
ctx.query.hasOwnProperty
calling an undefined method.I am using koa@2.11.0
The text was updated successfully, but these errors were encountered: