#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.

This commit is contained in:
Ezio Melotti 2013-03-13 01:52:34 +02:00
parent 7343cb0790
commit a7d64a6f4c
3 changed files with 15 additions and 5 deletions

View File

@ -167,7 +167,7 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
if nextchar == '}':
if object_pairs_hook is not None:
result = object_pairs_hook(pairs)
return result, end
return result, end + 1
pairs = {}
if object_hook is not None:
pairs = object_hook(pairs)

View File

@ -35,6 +35,12 @@ class TestDecode:
self.assertEqual(self.loads(s, object_pairs_hook=OrderedDict,
object_hook=lambda x: None),
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_decoder_optimizations(self):
# Several optimizations were made that skip over calls to

View File

@ -233,6 +233,10 @@ Core and Builtins
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 #14645: The email generator classes now produce output using the
specified linesep throughout. Previously if the prolog, epilog, or
body were stored with a different linesep, that linesep was used. This