-
Notifications
You must be signed in to change notification settings - Fork 2k
Change extend util to check hasOwnProperty #380
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
Conversation
|
Please add a test. |
|
@ryanseys - Added a test that fails before the changes to |
b5c14f5 to
6fae09c
Compare
|
Ahaha, jslint won't even let the build pass with it because extending Object is so bad. I guess we'll have to the scrap the test. I would highly suggest you don't extend native objects like that and would go as far to say that it's really not our fault if you do that and our code breaks because of it, but because this change is relatively straightforward and using hasOwnProperty is sort of "standard practice" in JavaScript due to limitations of |
|
@ryanseys - I added a jshint ignore for the one line, so we can keep the test around and not have travis complain. Generally agree with not extending native objects, but I believe |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Cool :) Thanks! Any way you could finally squash into 1 commit? Sorry for the troubles and thanks for your PR. |
Add test for extend function
0232f50 to
9554de3
Compare
|
No worries - was just in the middle of rebasing actually. 😸 |
Change extend util to check hasOwnProperty
|
Thanks! Released in |
|
I shall only add here as a tip that extending native objects this way is indeed considered a terrible practice exactly because of the side-effects you observed. If you really need to do so, you must do it "properly", making sure your extensions are not in an enumerable property. Object.defineProperty(Array.prototype, 'entries',
{ enumerable: false // default if omitted
, value: function entries () { /* logic here */ }
}
) |
|
@Alaneor - thanks for the tip. Realized that this was also causing a problem in request as well, and ended up switching to |
The lack of a
hasOwnPropertycheck can accidentally cause functions on the prototype to bubble up to being a parameter in an API request.For example... defining a polyfill:
will cause an extra
entriesparam to exist in a request in the query string, e.g.https://www.googleapis.com:443'/calendar/v3/calendars/stephen%40stephenwan.net/events?entries=.