#12051: merge with 3.1.

This commit is contained in:
Ezio Melotti 2011-05-11 01:10:27 +03:00
commit f188bc5d46
3 changed files with 38 additions and 3 deletions

View file

@ -16,6 +16,11 @@ class RecursiveJSONEncoder(json.JSONEncoder):
return 'JSONTestObject'
return json.JSONEncoder.default(o)
class EndlessJSONEncoder(json.JSONEncoder):
def default(self, o):
"""If check_circular is False, this will keep adding another list."""
return [o]
class TestRecursion(TestCase):
def test_listrecursion(self):
@ -67,7 +72,7 @@ class TestRecursion(TestCase):
self.fail("didn't raise ValueError on default recursion")
def test_highly_nested_objects(self):
def test_highly_nested_objects_decoding(self):
# test that loading highly-nested objects doesn't segfault when C
# accelerations are used. See #12017
with self.assertRaises(RuntimeError):
@ -77,3 +82,17 @@ class TestRecursion(TestCase):
with self.assertRaises(RuntimeError):
json.loads('[' * 100000 + '1' + ']' * 100000)
def test_highly_nested_objects_encoding(self):
# See #12051
l, d = [], {}
for x in range(100000):
l, d = [l], {'k':d}
with self.assertRaises(RuntimeError):
json.dumps(l)
with self.assertRaises(RuntimeError):
json.dumps(d)
def test_endless_recursion(self):
# See #12051
with self.assertRaises(RuntimeError):
EndlessJSONEncoder(check_circular=False).encode(5j)