stefankoegl / python-json-patch

Applying JSON Patches in Python
https://python-json-patch.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
434 stars 94 forks source link

take_index causing 'move' of incorrect values due to bad True==1 comparison #129

Closed Penguin2600 closed 3 years ago

Penguin2600 commented 3 years ago

See test here that reproduces the issue in code: https://gist.github.com/Penguin2600/bca88971424a13f45d3560acf0e60f45

Or simply look at this REPL output to understand the impact: Taken from line 714 of jsonpatch.py:

(Pdb) self.index_storage[st].keys()  
dict_keys([0.0, 1.0, 10.7, 'yes'])
(Pdb) stored = self.index_storage[st].get(True) 
(Pdb) len(stored)
1

In plain English, if my source data has a 1 or 1.0 anywhere and my destination data has a True anywhere jsonpatch will want to move 1.0 into the JSON where a true should be. This causes validation failures and in general incorrect output as in JSON '1.0' and 'true' are not the same thing.