Skip to content

Commit ae41173

Browse files
Copilotstefankoegl
andcommitted
Initial assessment and test case for bug fix
Co-authored-by: stefankoegl <184196+stefankoegl@users.noreply.github.com>
1 parent a499d23 commit ae41173

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,16 @@ def test_issue119(self):
526526
res = jsonpatch.apply_patch(src, patch)
527527
self.assertEqual(res, dst)
528528

529+
def test_numeric_string_dict_keys(self):
530+
"""Test the reported issue with numeric string dict keys"""
531+
src = {'1': 'def'}
532+
dst = {'test': '1', 'b': 'def'}
533+
# This should not raise an exception
534+
patch = jsonpatch.make_patch(src, dst)
535+
# Verify the patch works as expected
536+
res = jsonpatch.apply_patch(src, patch)
537+
self.assertEqual(res, dst)
538+
529539
def test_issue120(self):
530540
"""Make sure it avoids casting numeric str dict key to int"""
531541
src = [{'foobar': {'821b7213_b9e6_2b73_2e9c_cf1526314553': ['Open Work'],

tests/test_issue_bug.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
import jsonpatch
3+
4+
class IssueBugTestCase(unittest.TestCase):
5+
def test_numeric_string_dict_keys(self):
6+
"""Test the issue with numeric string dict keys"""
7+
src = {'1': 'def'}
8+
dst = {'test': '1', 'b': 'def'}
9+
# This should not raise an exception
10+
patch = jsonpatch.make_patch(src, dst)
11+
# Verify the patch works as expected
12+
applied = jsonpatch.apply_patch(src, patch)
13+
self.assertEqual(applied, dst)
14+
15+
if __name__ == '__main__':
16+
unittest.main()

0 commit comments

Comments
 (0)