]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport the relevant part of 2.192:
authorGuido van Rossum <guido@python.org>
Fri, 11 Oct 2002 00:09:51 +0000 (00:09 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 11 Oct 2002 00:09:51 +0000 (00:09 +0000)
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.

Objects/stringobject.c

index c601f606740d04610c797b5c5bebfbbd5f0ae943..8f7edaa70ed1566c48eddb8c1c05f2c7763a7836 100644 (file)
@@ -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