From a1eb2274943e86987fdd5a4c08ebd8c301522e3b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 11 Oct 2002 00:09:51 +0000 Subject: [PATCH] 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. --- Objects/stringobject.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 -- 2.47.3