We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d0bd351 commit f935d95Copy full SHA for f935d95
2 files changed
jsonpatch.py
@@ -880,17 +880,20 @@ def _compare_lists(self, path, src, dst):
880
for key in range(max_len):
881
if key < min_len:
882
old, new = src[key], dst[key]
883
- if old == new:
884
- continue
885
-
886
- elif isinstance(old, MutableMapping) and \
887
- isinstance(new, MutableMapping):
+ if isinstance(old, MutableMapping) and \
+ isinstance(new, MutableMapping):
888
self._compare_dicts(_path_join(path, key), old, new)
889
890
elif isinstance(old, MutableSequence) and \
891
isinstance(new, MutableSequence):
892
self._compare_lists(_path_join(path, key), old, new)
893
+ # To ensure we catch changes to JSON, we can't rely on a
+ # simple old == new, because it would not recognize the
+ # difference between 1 and True, among other things.
894
+ elif self.dumps(old) == self.dumps(new):
895
+ continue
896
+
897
else:
898
self._item_removed(path, key, old)
899
self._item_added(path, key, new)
tests.py
@@ -511,6 +511,16 @@ def test_issue103(self):
511
self.assertEqual(res, dst)
512
self.assertIsInstance(res['A'], float)
513
514
+ def test_issue180(self):
515
+ """In JSON 1 is different from True in list items even though in python 1 == True"""
516
+ src = {'aaa': [1, 1, 1]}
517
+ dst = {'aaa': [1, True, True]}
518
+ patch = jsonpatch.make_patch(src, dst)
519
+ res = jsonpatch.apply_patch(src, patch)
520
+ self.assertEqual(res, dst)
521
+ self.assertIsInstance(res['aaa'][1], bool)
522
+ self.assertIsInstance(res['aaa'][2], bool)
523
524
def test_issue119(self):
525
"""Make sure it avoids casting numeric str dict key to int"""
526
src = [
0 commit comments