Open zliang11 opened 3 years ago
Hi, @stefankoegl do you perhaps know where it isn't catching the index change?
I noticed that the error is probably caused by _undo_remove and _undo_add directly comparing the path and the key. It is very likely for nested lists that the index affected is not the key (last value) of its location. We can probably split the locations by '/', get the index of the key, then compare the value at that corresponding index to do the +,- changes.
I think this may be related: https://github.com/stefankoegl/python-json-patch/issues/138#issuecomment-1004469874
I found a bug with an example here that failed when applying the patch that was generated.
By looking at the patches, when 'b' is removed, the index for 'd' should be u'/1/0' but the patch still has u'2/0', which causes the error because u'/2' is now 'f', which is not a list, so it can't find it to do the "delete at /2/0 then add it back at /1" - the Move operation. I tested using this alternative jsondiff make function and it worked fine. https://github.com/nxsofsys/jsondiff