Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Penguin2600 committed Mar 12, 2021
1 parent 7a6d76a commit 5cdb066
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 8 additions & 6 deletions jsonpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,27 +699,29 @@ def __init__(self, src_doc, dst_doc, dumps=json.dumps, pointer_cls=JsonPointer):
root[:] = [root, root, None]

def store_index(self, value, index, st):
typed_key = (value, type(value))
try:
storage = self.index_storage[st]
stored = storage.get(value)
stored = storage.get(typed_key)
if stored is None:
storage[value] = [index]
storage[typed_key] = [index]
else:
storage[value].append(index)
storage[typed_key].append(index)

except TypeError:
self.index_storage2[st].append((value, index))
self.index_storage2[st].append((typed_key, index))

def take_index(self, value, st):
typed_key = (value, type(value))
try:
stored = self.index_storage[st].get(value)
stored = self.index_storage[st].get(typed_key)
if stored:
return stored.pop()

except TypeError:
storage = self.index_storage2[st]
for i in range(len(storage)-1, -1, -1):
if storage[i][0] == value:
if storage[i][0] == typed_key:
return storage.pop(i)[1]

def insert(self, op):
Expand Down
9 changes: 9 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,15 @@ def test_issue90(self):
self.assertEqual(res, dst)
self.assertIsInstance(res['A'], bool)

def test_issue129(self):
"""In JSON 1 is different from True even though in python 1 == True Take Two"""
src = {'A': {'D': 1.0}, 'B': {'E': 'a'}}
dst = {'A': {'C': 'a'}, 'B': {'C': True}}
patch = jsonpatch.make_patch(src, dst)
res = jsonpatch.apply_patch(src, patch)
self.assertEqual(res, dst)
self.assertIsInstance(res['B']['C'], bool)

def test_issue103(self):
"""In JSON 1 is different from 1.0 even though in python 1 == 1.0"""
src = {'A': 1}
Expand Down

0 comments on commit 5cdb066

Please sign in to comment.