-
Notifications
You must be signed in to change notification settings - Fork 94
Array diff bug #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
EWORKSFORME:
|
Ouch...it should be
Note, that it tries to move 2 from 0 element, but...there was no such value ever. without optimization jsonpatch produces more verbose, but semicorrect patch (at least it applies without problems):
I'll take a look tomorrow on fresh head. Btw, how about make jsonpatch validate which value it tries to move/remove? The last patch really believe that there is value 2 both on 0 and 1 positions, but that's not a true. |
Short update. I'm going to fix the way array patch been generated since there is another issue in whole algorithm: it uses to find out the longest common sequence for both arrays and build patch around it, but completely fails to provide reasonable patch for the case like this issue has: multiple short ranges of common values. |
@kxepal, any update on this? |
@stefankoegl sorry, will take a second look on weekends. First attempt to solve the issue became a mess and ugly so I abandon it for a while until better idea will come. May be will have better luck with second sight. |
Here's another example. One list is a permutation of the other: >>> a = ['23232812', '23232808', '23232807', '23232809', '23232811', '23232805', '23232810', '23232814', '23232806', '23232813']
>>> b = ['23232805', '23232806', '23232807', '23232808', '23232809', '23232810', '23232811', '23232812', '23232813', '23232814']
>>> import jsonpatch
>>> jsonpatch.match_patch(a, b).apply(a) == b
False |
Hello, you may try my small utility - https://github.com/nxsofsys/jsondiff
Moreover, my tool makes diffs really faster! Making diff of two arrays with 20000 random numbers is no problem. But some bugs exist I think =) |
So this is still an issue, and I think it's all about how _optimize combines operations like remove and add as replace and move operations. Let's say you replace the first command with a 'move' and delete the add: |
@domdom is correct: any operation that potentially changes the indexes of a range of elements (ie I think the only "trivial" optimisation is a |
Incidentally, this is the patch that gets produced for
do we know why the second My hand-made json patch for this change would be
which I arrived at by noticing that 1 and 2 are in the same order in the resultant list. I don't know how I'd put that down programatically (least of all in a nice generic way that would work in all cases). |
fixing array diff bug (issue #30)
This issue seems to be fixed at least in current
|
Great program, but I think I found a bug. These steps will reproduce it:
src = [1,2,3]
des = [3,1,4,2]
Create a patch from these then apply the patch to src. It will produce an index out of bounds exception.
The text was updated successfully, but these errors were encountered: