Support diffing keys named like Object.prototype properties #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #58.
Prior to this patch, the code assumed that input objects have a
hasOwnProperty
function, or that at least they will acquire one when passed throughutils.properObject
.However, this assumption is flawed: As noted in issue #58, when given input objects have a property on them called
hasOwnProperty
, it overrides the prototype's function property that the code relied on, causing any diffing function to error out withThe solution taken in this PR is to forget about
utils.properObject
, and instead introduceutils.hasOwnProperty
which usesObject.prototype.hasOwnProperty.call
instead of assuming anything about the input object, and replacing all directinputObject.hasOwnProperty
calls with it instead.Tests are separate in 401457d, for ease of checking that they fail initially.
Also separate in e310b60 is automatic checking for this type of issue through eslint, which includes the no-prototype-builtins rule in its default recommended set, as suggested by @papb. All other eslint rules passed without modification. It is in a separate commit in case you are not interested in taking on a dev dependency.