File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -175,7 +175,11 @@ def make_patch(src, dst):
175175 # TODO: fix patch optimiztion and remove the following check
176176 # fix when patch with optimization is incorrect
177177 patch = JsonPatch .from_diff (src , dst )
178- new = patch .apply (src )
178+ try :
179+ new = patch .apply (src )
180+ except JsonPatchConflict : # see TODO
181+ return JsonPatch .from_diff (src , dst , False )
182+
179183 if new != dst :
180184 return JsonPatch .from_diff (src , dst , False )
181185
@@ -601,7 +605,6 @@ def _longest_common_subseq(src, dst):
601605 matrix [i ][j ] = matrix [i - 1 ][j - 1 ] + 1
602606 if matrix [i ][j ] > z :
603607 z = matrix [i ][j ]
604- if matrix [i ][j ] == z :
605608 range_src = (i - z + 1 , i + 1 )
606609 range_dst = (j - z + 1 , j + 1 )
607610 else :
Original file line number Diff line number Diff line change @@ -376,7 +376,15 @@ def test_json_patch(self):
376376 patch = jsonpatch .make_patch (old , new )
377377 new_from_patch = jsonpatch .apply_patch (old , patch )
378378 self .assertEqual (new , new_from_patch )
379-
379+
380+ def test_arrays_one_element_sequences (self ):
381+ """ Tests the case of multiple common one element sequences inside an array """
382+ # see https://github.com/stefankoegl/python-json-patch/issues/30#issuecomment-155070128
383+ src = [1 ,2 ,3 ]
384+ dst = [3 ,1 ,4 ,2 ]
385+ patch = jsonpatch .make_patch (src , dst )
386+ res = jsonpatch .apply_patch (src , patch )
387+ self .assertEqual (res , dst )
380388
381389class OptimizationTests (unittest .TestCase ):
382390 def test_use_replace_instead_of_remove_add (self ):
You can’t perform that action at this time.
0 commit comments