Skip to content

Commit 33e630e

Browse files
authored
Merge pull request #99 from itkach/master
Fix move for numeric dictionary keys (issue #97)
2 parents 2990bb3 + 53817c0 commit 33e630e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

jsonpatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
# Will be parsed by setup.py to determine package metadata
5858
__author__ = 'Stefan Kögl <stefan@skoegl.net>'
59-
__version__ = '1.22'
59+
__version__ = '1.24'
6060
__website__ = 'https://github.com/stefankoegl/python-json-patch'
6161
__license__ = 'Modified BSD License'
6262

@@ -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)