-
Notifications
You must be signed in to change notification settings - Fork 138
Node6 incompatibilities with querystrings
#571
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
Comments
Node 6 has been out of support for quite a time now. Is it also reproducible in newer versions of Node? |
Yes, I can't remember exactly which versions I've tried it with, but the latest (14.x) docs state that
Of course, this is only an issue when passing the parsed |
I do this on server side middleware for requests:
// Patch request query to be an object for operating on it as an Object
// this is because node.js strips down the prototype for performance/speed
(ctx, next) => {
if (ctx.request.query && typeof ctx.request.query === 'object') {
// node.js removed the Object.prototype on querystring nodejs/node#6055
// coerce query to inherit from Object.prototype
const def = {
value: { ...ctx.request.query },
writable: false,
}
Object.defineProperty(ctx.request, 'query', def)
Object.defineProperty(ctx, 'query', def)
}
return next()
},
… On Jul 13, 2020, at 12:41 PM, cmidkiff87 ***@***.***> wrote:
Yes, I can't remember exactly which versions I've tried it with, but the latest (14.x) docs <https://nodejs.org/docs/latest-v14.x/api/querystring.html#querystring_querystring_parse_str_sep_eq_options> state that
The object returned by the querystring.parse() method does not prototypically inherit from the JavaScript Object. This means that typical Object methods such as obj.toString(), obj.hasOwnProperty(), and others are not defined and will not work.
Of course, this is only an issue when passing the parsed querystring object directly to js-data (as we have), and is "fixable" by shimming the object with the required functions.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#571 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABNSMS3IRAHG4AZDGT5YE63R3NPORANCNFSM4ODAKVUA>.
|
Then perhaps there should be a note about this somewhere in the documentation, rather than updating js-data? (since this is probably more of an issue for upgrading legacy projects than it is for new projects) |
I’m not sure that I see this is anything specific to js-data itself, it’s a Node.js quark.
… On Jul 13, 2020, at 12:55 PM, cmidkiff87 ***@***.***> wrote:
Then perhaps there should be a note about this somewhere in the documentation, rather than updating js-data?
(since this is probably more of an issue for upgrading legacy projects than it is for new projects)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#571 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABNSMS45DQJ4ARL6NF6MBULR3NRE5ANCNFSM4ODAKVUA>.
|
I think it might be handy to add this as some utility to js-data, which can
be optionally called if required and print some warnings in console when it
comes to the described situation with the advice to run this utility
пн, 13 лип. 2020 о 12:55 cmidkiff87 <notifications@github.com> пише:
… Then perhaps there should be a note about this somewhere in the
documentation, rather than updating js-data?
(since this is probably more of an issue for upgrading legacy projects
than it is for new projects)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#571 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABAJO6BXD7TMU6EGSJ2YTI3R3NRE5ANCNFSM4ODAKVUA>
.
|
Uh oh!
There was an error while loading. Please reload this page.
Node 6 changed the
querystring.parse
to return an object whose__proto__
property no longer points back toObject
. This was done to allow for more esoteric query string names, such ashttps://example.com/route?__proto__=some-value
, which would conflict with the native js object properties.However, this causes js-data to error when calling
hasOwnProperty()
if you pass it thequerystring
object.This is especially problematic when using js-data-http as it automatically sends the requests with the url's query strings in the format js-data expects.
It can be fixed by using
in place of
The libraries involved are
It can also be fixed externally by shimming the
hasOwnProperty()
function onto the querystringHowever, that solution isn't super intuitive without some digging
The text was updated successfully, but these errors were encountered: