From: Benjamin Peterson Date: Mon, 23 Apr 2012 14:55:29 +0000 (-0400) Subject: inherit maxchar of field value where needed (closes #14648) X-Git-Tag: v3.3.0a3~110 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80d07f825108761af9fe2ac79c1ef50289c07c08;p=thirdparty%2FPython%2Fcpython.git inherit maxchar of field value where needed (closes #14648) --- diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 813d59fd3c7d..7b0397ef7e68 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1056,6 +1056,8 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual('%f' % INF, 'inf') self.assertEqual('%F' % INF, 'INF') + self.assertEqual(format("\u0410\u0411\u0412", "s"), "АБВ") + def test_startswith_endswith_errors(self): for meth in ('foo'.startswith, 'foo'.endswith): with self.assertRaises(TypeError) as cm: diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 58e66e0d90c5..5e5b19f7feab 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -747,6 +747,9 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format) len = format->precision; } + if (len) + maxchar = PyUnicode_MAX_CHAR_VALUE(value); + calc_padding(len, format->width, format->align, &lpad, &rpad, &total); if (lpad != 0 || rpad != 0)