From: Guido van Rossum Date: Fri, 11 Oct 2002 00:09:51 +0000 (+0000) Subject: Backport the relevant part of 2.192: X-Git-Tag: v2.2.2~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1eb2274943e86987fdd5a4c08ebd8c301522e3b;p=thirdparty%2FPython%2Fcpython.git Backport the relevant part of 2.192: The string formatting code has a test to switch to Unicode when %s sees a Unicode argument. Unfortunately this test was also executed for %r, because %s and %r share almost all of their code. This meant that, if u is a unicode object while repr(u) is an 8-bit string containing ASCII characters, '%r' % u is a *unicode* string containing only ASCII characters! Fixed by executing the test only for %s. --- diff --git a/Objects/stringobject.c b/Objects/stringobject.c index c601f606740d..8f7edaa70ed1 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -3502,7 +3502,6 @@ PyString_Format(PyObject *format, PyObject *args) len = 1; break; case 's': - case 'r': #ifdef Py_USING_UNICODE if (PyUnicode_Check(v)) { fmt = fmt_start; @@ -3510,6 +3509,8 @@ PyString_Format(PyObject *format, PyObject *args) goto unicode; } #endif + /* Fall through */ + case 'r': if (c == 's') temp = PyObject_Str(v); else