kpdecker / jsdiff

A javascript text differencing implementation.
BSD 3-Clause "New" or "Revised" License
8.04k stars 499 forks source link

diffJson throws on `Object.create(null)` in some cases #492

Closed danbeam closed 7 months ago

danbeam commented 7 months ago

Minimal repro:

diffJson(Object.assign(Object.create(null), {a: 123}), {b: 456});

With an error like:

/.../node_modules/diff/src/diff/json.js:68
      if (obj.hasOwnProperty(key)) {
              ^
TypeError: obj.hasOwnProperty is not a function

As far as I can tell, some popular libraries export object with these setups (e.g. eslint and express). I believe I have a simple fix.