From 4a90ef03637fdc1bc63ee9be82fbf22cbaa68662 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 3 Mar 2012 02:35:32 +0100 Subject: =?UTF-8?q?Issue=20#14177:=20marshal.loads()=20now=20raises=20Type?= =?UTF-8?q?Error=20when=20given=20an=20unicode=20string.=20Patch=20by=20Gu?= =?UTF-8?q?ilherme=20Gon=C3=A7alves.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/test/test_exceptions.py | 2 +- Lib/test/test_marshal.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 0a7ddd4c5b..7a2dd0c8f1 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -38,7 +38,7 @@ class ExceptionTests(unittest.TestCase): try: try: import marshal - marshal.loads('') + marshal.loads(b'') except EOFError: pass finally: diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index 9a250120ed..96a70ecc2a 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -184,7 +184,7 @@ class BugsTestCase(unittest.TestCase): pass def test_loads_recursion(self): - s = 'c' + ('X' * 4*4) + '{' * 2**20 + s = b'c' + (b'X' * 4*4) + b'{' * 2**20 self.assertRaises(ValueError, marshal.loads, s) def test_recursion_limit(self): @@ -257,6 +257,11 @@ class BugsTestCase(unittest.TestCase): finally: support.unlink(support.TESTFN) + def test_loads_reject_unicode_strings(self): + # Issue #14177: marshal.loads() should not accept unicode strings + unicode_string = 'T' + self.assertRaises(TypeError, marshal.loads, unicode_string) + def test_main(): support.run_unittest(IntTestCase, -- cgit v1.2.1