jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Error when comparing arrays with `null`and Object elements (in the demo website).

Open bernharduw opened this issue 7 years ago • 3 comments

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:

image

bernharduw avatar Apr 07 '17 15:04 bernharduw

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

benjamine avatar Apr 07 '17 17:04 benjamine

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

bernharduw avatar Apr 11 '17 10:04 bernharduw

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).

benjamine avatar Apr 11 '17 19:04 benjamine