jsondiffpatch
jsondiffpatch copied to clipboard
Error when comparing arrays with `null`and Object elements (in the demo website).
Comparing arrays with elements of different types usually works perfectly, but comparing [null]
with [{}]
throws an error.
I came across this while trying to find the difference of two quite complex JSON docs, but the Demo site didn't show any differences at all. Only at closer examination I found out that there was an error on the console.
I'm not quite certain if this is only an error in the demo website or in the library itself. Here's the screenshot:
I see, yes, it's an error in the objectHash
function used in the demo page, maybe the lib could prevent this with extra checks? but this would be fixed if objectHash
function weren't assuming the values are never null
https://github.com/benjamine/jsondiffpatch/blob/master/public/demo/demo.js#L136
Would you prefer to set the obj
to an empty object if null, or wrap all checks with an if (typeof obj === 'object') {…}
condition?
https://github.com/benjamine/jsondiffpatch/blob/master/public/demo/demo.js#L136
I think typeof null === object
, I don't know, this is a bit on user-space, but I think for the demo if obj === null, I would go to the fallback there (return a string based on the item index).