diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-02-23 23:20:14 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-02-23 23:20:14 (GMT) |
commit | f7270ba58f70c8e1b61fe5db333ce51adf6ed0fa (patch) | |
tree | 666b14cd14a56b5d5eddf53f12872ac957ecfc2a /Objects/unicodeobject.c | |
parent | 35523dc8992b7c21c5a4b3cf2b0a41ff2c20dd72 (diff) | |
download | cpython-f7270ba58f70c8e1b61fe5db333ce51adf6ed0fa.zip cpython-f7270ba58f70c8e1b61fe5db333ce51adf6ed0fa.tar.gz cpython-f7270ba58f70c8e1b61fe5db333ce51adf6ed0fa.tar.bz2 |
Merged revisions 78392 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78392 | victor.stinner | 2010-02-24 00:16:07 +0100 (mer., 24 févr. 2010) | 4 lines
Issue #7649: Fix u'%c' % char for character in range 0x80..0xFF
=> raise an UnicodeDecodeError. Patch written by Ezio Melotti.
........
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3731ac7..667afae 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8357,6 +8357,7 @@ formatchar(Py_UNICODE *buf, size_t buflen, PyObject *v) { + PyObject *s; /* presume that the buffer is at least 2 characters long */ if (PyUnicode_Check(v)) { if (PyUnicode_GET_SIZE(v) != 1) @@ -8367,7 +8368,14 @@ formatchar(Py_UNICODE *buf, else if (PyString_Check(v)) { if (PyString_GET_SIZE(v) != 1) goto onError; - buf[0] = (Py_UNICODE)PyString_AS_STRING(v)[0]; + /* #7649: if the char is a non-ascii (i.e. in range(0x80,0x100)) byte + string, "u'%c' % char" should fail with a UnicodeDecodeError */ + s = PyUnicode_FromStringAndSize(PyString_AS_STRING(v), 1); + /* if the char is not decodable return -1 */ + if (s == NULL) + return -1; + buf[0] = PyUnicode_AS_UNICODE(s)[0]; + Py_DECREF(s); } else { |