Skip to content

Commit 1b83d63

Browse files
author
Igor Tkach
committed
Fix move for numeric dictionary keys (issue stefankoegl#97)
1 parent 2990bb3 commit 1b83d63

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

jsonpatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def _item_added(self, path, key, item):
717717
index = self.take_index(item, _ST_REMOVE)
718718
if index is not None:
719719
op = index[2]
720-
if type(op.key) == int:
720+
if type(op.key) == int and type(key) == int:
721721
for v in self.iter_from(index):
722722
op.key = v._on_undo_remove(op.path, op.key)
723723

tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ def test_nested(self):
419419
new_from_patch = jsonpatch.apply_patch(old, patch)
420420
self.assertEqual(new, new_from_patch)
421421

422+
def test_move_from_numeric_to_alpha_dict_key(self):
423+
#https://github.com/stefankoegl/python-json-patch/issues/97
424+
src = {'13': 'x'}
425+
dst = {'A': 'a', 'b': 'x'}
426+
patch = jsonpatch.make_patch(src, dst)
427+
res = jsonpatch.apply_patch(src, patch)
428+
self.assertEqual(res, dst)
429+
430+
422431

423432
class OptimizationTests(unittest.TestCase):
424433
def test_use_replace_instead_of_remove_add(self):

0 commit comments

Comments
 (0)