cpython: 4966907d3661 (original) (raw)
Mercurial > cpython
changeset 75374:4966907d3661 3.2
Issue #14177: marshal.loads() now raises TypeError when given an unicode string. Patch by Guilherme Gonçalves. [#14177]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Sat, 03 Mar 2012 02:35:32 +0100 |
parents | 185a6ae76479 |
children | e67b3a9bd2dc 5a2bc0d574f6 |
files | Lib/test/test_exceptions.py Lib/test/test_marshal.py Misc/ACKS Misc/NEWS Python/marshal.c |
diffstat | 5 files changed, 15 insertions(+), 6 deletions(-)[+] [-] Lib/test/test_exceptions.py 2 Lib/test/test_marshal.py 7 Misc/ACKS 1 Misc/NEWS 3 Python/marshal.c 8 |
line wrap: on
line diff
--- 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('')[](#l1.7)
marshal.loads(b'')[](#l1.8) except EOFError:[](#l1.9) pass[](#l1.10) finally:[](#l1.11)
--- 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[](#l2.7)
s = b'c' + (b'X' * 4*4) + b'{' * 2**20[](#l2.8) self.assertRaises(ValueError, marshal.loads, s)[](#l2.9)
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[](#l2.17)
unicode_string = 'T'[](#l2.18)
self.assertRaises(TypeError, marshal.loads, unicode_string)[](#l2.19)
+ def test_main(): support.run_unittest(IntTestCase,
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -341,6 +341,7 @@ Johannes Gijsbers Michael Gilfix Christoph Gohlke Tim Golden +Guilherme Gonçalves Chris Gonnerman David Goodger Hans de Graaff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -130,6 +130,9 @@ Core and Builtins Library ------- +- Issue #14177: marshal.loads() now raises TypeError when given an unicode
- Issue #14159: Fix the len() of weak containers (WeakSet, WeakKeyDictionary, WeakValueDictionary) to return a better approximation when some objects are dead or dying. Moreover, the implementation is now O(1) rather than
--- a/Python/marshal.c +++ b/Python/marshal.c @@ -1383,7 +1383,7 @@ marshal_loads(PyObject *self, PyObject * char s; Py_ssize_t n; PyObject result;
- if (!PyArg_ParseTuple(args, "y*:loads", &p)) return NULL; s = p.buf; n = p.len; @@ -1400,10 +1400,10 @@ marshal_loads(PyObject *self, PyObject * }
PyDoc_STRVAR(loads_doc, -"loads(string)\n[](#l5.16) +"loads(bytes)\n[](#l5.17) \n[](#l5.18) -Convert the string to a value. If no valid value is found, raise\n[](#l5.19) -EOFError, ValueError or TypeError. Extra characters in the string are\n[](#l5.20) +Convert the bytes object to a value. If no valid value is found, raise\n[](#l5.21) +EOFError, ValueError or TypeError. Extra characters in the input are\n[](#l5.22) ignored."); static PyMethodDef marshal_methods[] = {