Commit fda7a8ce authored by Ezio Melotti's avatar Ezio Melotti

#17368: Fix an off-by-one error in the Python JSON decoder that caused a...

#17368: Fix an off-by-one error in the Python JSON decoder that caused a failure while decoding empty object literals when object_pairs_hook was specified.
parent 981c3bde
...@@ -163,7 +163,7 @@ def JSONObject(s_and_end, encoding, strict, scan_once, object_hook, ...@@ -163,7 +163,7 @@ def JSONObject(s_and_end, encoding, strict, scan_once, object_hook,
if nextchar == '}': if nextchar == '}':
if object_pairs_hook is not None: if object_pairs_hook is not None:
result = object_pairs_hook(pairs) result = object_pairs_hook(pairs)
return result, end return result, end + 1
pairs = {} pairs = {}
if object_hook is not None: if object_hook is not None:
pairs = object_hook(pairs) pairs = object_hook(pairs)
......
...@@ -40,10 +40,15 @@ class TestDecode(object): ...@@ -40,10 +40,15 @@ class TestDecode(object):
self.assertEqual(od, OrderedDict(p)) self.assertEqual(od, OrderedDict(p))
self.assertEqual(type(od), OrderedDict) self.assertEqual(type(od), OrderedDict)
# the object_pairs_hook takes priority over the object_hook # the object_pairs_hook takes priority over the object_hook
self.assertEqual(self.loads(s, self.assertEqual(self.loads(s, object_pairs_hook=OrderedDict,
object_pairs_hook=OrderedDict,
object_hook=lambda x: None), object_hook=lambda x: None),
OrderedDict(p)) OrderedDict(p))
# check that empty objects literals work (see #17368)
self.assertEqual(self.loads('{}', object_pairs_hook=OrderedDict),
OrderedDict())
self.assertEqual(self.loads('{"empty": {}}',
object_pairs_hook=OrderedDict),
OrderedDict([('empty', OrderedDict())]))
def test_extra_data(self): def test_extra_data(self):
s = '[1, 2, 3]5' s = '[1, 2, 3]5'
......
...@@ -214,6 +214,10 @@ Core and Builtins ...@@ -214,6 +214,10 @@ Core and Builtins
Library Library
------- -------
- Issue #17368: Fix an off-by-one error in the Python JSON decoder that caused
a failure while decoding empty object literals when object_pairs_hook was
specified.
- Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when - Issue #17278: Fix a crash in heapq.heappush() and heapq.heappop() when
the list is being resized concurrently. the list is being resized concurrently.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment