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):
175
175
# TODO: fix patch optimiztion and remove the following check
176
176
# fix when patch with optimization is incorrect
177
177
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
+
179
183
if new != dst :
180
184
return JsonPatch .from_diff (src , dst , False )
181
185
@@ -601,7 +605,6 @@ def _longest_common_subseq(src, dst):
601
605
matrix [i ][j ] = matrix [i - 1 ][j - 1 ] + 1
602
606
if matrix [i ][j ] > z :
603
607
z = matrix [i ][j ]
604
- if matrix [i ][j ] == z :
605
608
range_src = (i - z + 1 , i + 1 )
606
609
range_dst = (j - z + 1 , j + 1 )
607
610
else :
Original file line number Diff line number Diff line change @@ -376,7 +376,15 @@ def test_json_patch(self):
376
376
patch = jsonpatch .make_patch (old , new )
377
377
new_from_patch = jsonpatch .apply_patch (old , patch )
378
378
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 )
380
388
381
389
class OptimizationTests (unittest .TestCase ):
382
390
def test_use_replace_instead_of_remove_add (self ):
You can’t perform that action at this time.
0 commit comments