kpdecker / jsdiff

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

Support `Object.create(null)` in JSON diffing #493

Closed danbeam closed 4 months ago

danbeam commented 4 months ago

Addresses https://github.com/kpdecker/jsdiff/issues/492

I was recently trying to use diff to compare output from a library that makes use of Object.create(null). This seems valid (if not encouraged) in some situations, but diff was throwing as the typeof this is 'object' and it is !== null but obj.hasOwnProperty does not exist.

Instead, use Object.prototype.hasOwnProperty.call(obj, key) similar to the way that Object.prototyope.toString is used elsewhere in this library.