summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-03-12 23:49:57 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-03-12 23:49:57 (GMT)
commitfda7a8ce78cdc46c6728ad9cd82c4b3eccd0dd92 (patch)
treea47ff8b56cf3a15d4056da86ac92bda314514be4
parent981c3bde8de59bd516f26e435d01788df3d5de56 (diff)
downloadcpython-fda7a8ce78cdc46c6728ad9cd82c4b3eccd0dd92.zip
cpython-fda7a8ce78cdc46c6728ad9cd82c4b3eccd0dd92.tar.gz
cpython-fda7a8ce78cdc46c6728ad9cd82c4b3eccd0dd92.tar.bz2
#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.
-rw-r--r--Lib/json/decoder.py2
-rw-r--r--Lib/json/tests/test_decode.py9
-rw-r--r--Misc/NEWS4
3 files changed, 12 insertions, 3 deletions
diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
index dc8916c..dfcc628 100644
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -163,7 +163,7 @@ def JSONObject(s_and_end, encoding, strict, scan_once, object_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)
diff --git a/Lib/json/tests/test_decode.py b/Lib/json/tests/test_decode.py
index 478a16b..ffd1aa4 100644
--- a/Lib/json/tests/test_decode.py
+++ b/Lib/json/tests/test_decode.py
@@ -40,10 +40,15 @@ class TestDecode(object):
self.assertEqual(od, OrderedDict(p))
self.assertEqual(type(od), OrderedDict)
# the object_pairs_hook takes priority over the object_hook
- self.assertEqual(self.loads(s,
- object_pairs_hook=OrderedDict,
+ 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_extra_data(self):
s = '[1, 2, 3]5'
diff --git a/Misc/NEWS b/Misc/NEWS
index 992b70e..d861538 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -214,6 +214,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 #17278: Fix a crash in heapq.heappush() and heapq.heappop() when
the list is being resized concurrently.