summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonpatch.py2
-rwxr-xr-xtests.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/jsonpatch.py b/jsonpatch.py
index 4f8a02b..bf6a1b5 100644
--- a/jsonpatch.py
+++ b/jsonpatch.py
@@ -717,7 +717,7 @@ class DiffBuilder(object):
index = self.take_index(item, _ST_REMOVE)
if index is not None:
op = index[2]
- if type(op.key) == int:
+ if type(op.key) == int and type(key) == int:
for v in self.iter_from(index):
op.key = v._on_undo_remove(op.path, op.key)
diff --git a/tests.py b/tests.py
index cd39b3b..07f923b 100755
--- a/tests.py
+++ b/tests.py
@@ -419,6 +419,15 @@ class MakePatchTestCase(unittest.TestCase):
new_from_patch = jsonpatch.apply_patch(old, patch)
self.assertEqual(new, new_from_patch)
+ def test_move_from_numeric_to_alpha_dict_key(self):
+ #https://github.com/stefankoegl/python-json-patch/issues/97
+ src = {'13': 'x'}
+ dst = {'A': 'a', 'b': 'x'}
+ patch = jsonpatch.make_patch(src, dst)
+ res = jsonpatch.apply_patch(src, patch)
+ self.assertEqual(res, dst)
+
+
class OptimizationTests(unittest.TestCase):
def test_use_replace_instead_of_remove_add(self):