Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 220391f

Browse files
committed
#17368: merge with 3.2.
2 parents 72cdb5c + a7d64a6 commit 220391f

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

Lib/json/decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
166166
if nextchar == '}':
167167
if object_pairs_hook is not None:
168168
result = object_pairs_hook(pairs)
169-
return result, end
169+
return result, end + 1
170170
pairs = {}
171171
if object_hook is not None:
172172
pairs = object_hook(pairs)

Lib/test/json_tests/test_decode.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ def test_object_pairs_hook(self):
2525
p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
2626
("qrt", 5), ("pad", 6), ("hoy", 7)]
2727
self.assertEqual(self.loads(s), eval(s))
28-
self.assertEqual(self.loads(s, object_pairs_hook = lambda x: x), p)
28+
self.assertEqual(self.loads(s, object_pairs_hook=lambda x: x), p)
2929
self.assertEqual(self.json.load(StringIO(s),
3030
object_pairs_hook=lambda x: x), p)
31-
od = self.loads(s, object_pairs_hook = OrderedDict)
31+
od = self.loads(s, object_pairs_hook=OrderedDict)
3232
self.assertEqual(od, OrderedDict(p))
3333
self.assertEqual(type(od), OrderedDict)
3434
# the object_pairs_hook takes priority over the object_hook
35-
self.assertEqual(self.loads(s, object_pairs_hook = OrderedDict,
36-
object_hook = lambda x: None),
35+
self.assertEqual(self.loads(s, object_pairs_hook=OrderedDict,
36+
object_hook=lambda x: None),
3737
OrderedDict(p))
38+
# check that empty objects literals work (see #17368)
39+
self.assertEqual(self.loads('{}', object_pairs_hook=OrderedDict),
40+
OrderedDict())
41+
self.assertEqual(self.loads('{"empty": {}}',
42+
object_pairs_hook=OrderedDict),
43+
OrderedDict([('empty', OrderedDict())]))
3844

3945
def test_decoder_optimizations(self):
4046
# Several optimizations were made that skip over calls to

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ Core and Builtins
193193
Library
194194
-------
195195

196+
- Issue #17368: Fix an off-by-one error in the Python JSON decoder that caused
197+
a failure while decoding empty object literals when object_pairs_hook was
198+
specified.
199+
196200
- Issue #14645: The email generator classes now produce output using the
197201
specified linesep throughout. Previously if the prolog, epilog, or
198202
body were stored with a different linesep, that linesep was used. This

0 commit comments

Comments
 (0)