Description
I'm trying to use deep-object-diff to compare different copies of https://github.com/mdn/browser-compat-data, which is a dataset describing the web platform itself. As such, it has a key called "hasOwnProperty" to describe that method. deep-object-diff uses code like obj.hasOwnProperty(key)
a lot, and obj.hasOwnProperty
will in this case be an object in the BCD data, not Object.prototype.hasOwnProperty
.
This causes deep-object-diff to throw an exception, the first place being here.
deep-object-diff/src/diff/index.js
Line 12 in 45549c8
Simplified a bit, here's a subset of the data:
{
"javascript": {
"builtins": {
"Object": {
"hasOwnProperty": {
"__compat": "an object with more stuff here"
}
}
}
}
}
Repro script showing the problem:
const { diff } = require("deep-object-diff");
diff({"hasOwnProperty": 1}, {"hasOwnProperty": 2});
This will throw "Uncaught TypeError: r.hasOwnProperty is not a function".
A possible fix for this would be to add a hasOwnProperty
wrapper to https://github.com/mattphillips/deep-object-diff/blob/master/src/utils/index.js and always use that, but there may be other ways.
Activity
papb commentedon Oct 6, 2020
https://eslint.org/docs/rules/no-prototype-builtins would catch that.
Add failing tests for mattphillips#58
Support diffing keys named like Object.prototype properties
Add eslint to enforce no-prototype-builtins
anko commentedon Oct 9, 2020
@foolip Review #59?
(Posting this because I think you don't get a notification when a PR links to your issue.)
foolip commentedon Oct 21, 2020
@anko thanks for posting the fix, I've tried it and can confirm it fixes my problem.
Add failing tests for mattphillips#58
Support diffing keys named like Object.prototype properties
Add eslint to enforce no-prototype-builtins
Add failing tests for #58
Support diffing keys named like Object.prototype properties
Add eslint to enforce no-prototype-builtins
mattphillips commentedon Jan 25, 2022
Available in v1.1.5