-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(*): do not rely on an object's hasOwnProperty #2141
Conversation
Merely testing for object[key] will give incorrect results on keys defined in Object.prototype.
PR Checklist (Minor Bugfix)
|
Not sure what happened to Travis – I have Firefox 19 on Ubuntu 12.04 here, and it passed @IgorMinar I can certainly see your concerns about performance. While most of these places could hypothetically see a conflict, they are constrained to developer actions, and as such are extremely unlikely to happen and very easy to avoid. I will clean up this PR and only patch places that could conceivably receive keys out of the developer's control. Regarding the CLA: I did sign it before, as Daniel Luz, and I have a few patches merged in already. |
thnx. btw travis has been a bit flaky lately - don't worry about it much as long as tests are passing locally. |
@mernen - did you make the changes suggested by @IgorMinar yet? |
FYI: to verify that this occurs easily in the wild, doing something like this:
caused getterFnCache["hasOwnProperty"] to be set, breaking future cache look ups. |
@mernen - are you able to make these changes to this PR? |
Merely testing for object[key] will give incorrect results on keys defined in Object.prototype. Note: IE8 is generally broken in this regard since `for...in` never returns certain property keys even if they are defined directly on the object. See #2141 - partially merges this PR
Merely testing for object[key] will give incorrect results on keys defined in Object.prototype. Note: IE8 is generally broken in this regard since `for...in` never returns certain property keys even if they are defined directly on the object. See #2141 - partially merges this PR
@barries nice bug find: I can imagine $parse breaking if I see that @petebacondarwin is making the changes already. |
Merely testing for object[key] will give incorrect results on keys defined in Object.prototype. Note: IE8 is generally broken in this regard since `for...in` never returns certain property keys even if they are defined directly on the object. See angular#2141 - partially merges this PR
@barries - I can't actually get your suggested "in the wild" bug to fail. Any chance you could create a failing spec for it? I tried:
|
is 1865ea9 ready to be merged? |
Sadly it breaks on IE8. More work needed. On 24 July 2013 17:38, Igor Minar [email protected] wrote:
|
Actually, considering the reasoning from this commit: 7829c50#L1R275 |
I have a new pull request for all of this, see #3331, so closing. |
As noted by #1944, AngularJS currently relies in several places on an object's own
.hasOwnProperty()
method. This will break when said object does not inherit fromObject.prototype
, or when this key is redefined.This patch is inspired by jQuery's approach to the problem.
Caveats
Object.create(null)
were included, as they would break on old versions of IE; however, their practical effect is the same as redefininghasOwnProperty
toundefined
.hasOwnProperty
might be called would needlessly dilute the tests.