jsondiff
jsondiff copied to clipboard
Bug when second list is empty
Kind of a bug:
>>> import jsondiff
>>> a = []
>>> b = ['a', 'b', 'c']
>>> jsondiff.diff(a,b)
['a', 'b', 'c'] # ok
>>> jsondiff.diff(b,a)
[] # wrong. expected: {delete: [3, 2, 1]}
>>> jsondiff.diff(b,a, syntax='explicit')
[] # wrong. expected: {delete: [3, 2, 1]}
>>> jsondiff.diff(a,b, syntax='symmetric')
[[], ['a', 'b', 'c']] # ok ?
Hello @KKomarov,
Please check out #4 for some insight into this behaviour. In this case, jsondiff considers the two lists to be completely different therefore represents the difference as a substitution rather than a patch. It is perhaps debatable whether this is the best default behaviour in the explicit case, but it's a design choice not a bug.
Hope this helps.
@ericremoreynolds Thank you, I agree there is no problem with symmetric
syntax. But others syntaxes have problems.
# another example
>>> from jsondiff import diff
>>> diff(['a', 'b', 'c'], ['a', 'c'])
{delete: [1]}
>>> diff(['a', 'b', 'c'], ['a'])
{delete: [2, 1]}
>>> diff(['a', 'b', 'c'], []) # bug is here
[]
Adding to this, jsondiff unexpectedly returned a list when one of the comparitor is an empty dict.
>>> jsondiff.diff({'a': 30},{},syntax='symmetric')
[{'a': 30}, {}]
>>> jsondiff.diff({},{'a': 20},syntax='symmetric')
[{}, {'a': 20}]