diff options
author | Marc-André Lemburg <mal@egenix.com> | 2001-05-02 14:21:53 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2001-05-02 14:21:53 (GMT) |
commit | 542fe56cb9ed36bd8af8bd5cbfba9cdc7f3514f0 (patch) | |
tree | f922b0ff8a38e28912bd5c962ada6c4e8e2e636a | |
parent | 0e57abf0cdc7cd3f8cca518ded422d782587740c (diff) | |
download | cpython-542fe56cb9ed36bd8af8bd5cbfba9cdc7f3514f0.zip cpython-542fe56cb9ed36bd8af8bd5cbfba9cdc7f3514f0.tar.gz cpython-542fe56cb9ed36bd8af8bd5cbfba9cdc7f3514f0.tar.bz2 |
Fix for bug #417030: "print '%*s' fails for unicode string"
-rw-r--r-- | Lib/test/test_unicode.py | 6 | ||||
-rw-r--r-- | Objects/stringobject.c | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index d775516..0df8217 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -366,6 +366,12 @@ verify('...%(foo)s...' % {u'foo':u"abc",u'def':123} == u'...abc...') verify('...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...1...2...3...abc...') verify('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...%...%s...1...2...3...abc...') verify('...%s...' % u"abc" == u'...abc...') +verify('%*s' % (5,u'abc',) == u' abc') +verify('%*s' % (-5,u'abc',) == u'abc ') +verify('%*.*s' % (5,2,u'abc',) == u' ab') +verify('%*.*s' % (5,3,u'abc',) == u' abc') +verify('%i %*.*s' % (10, 5,3,u'abc',) == u'10 abc') +verify('%i%s %*.*s' % (10, 3, 5,3,u'abc',) == u'103 abc') print 'done.' # Test builtin codecs diff --git a/Objects/stringobject.c b/Objects/stringobject.c index bf5056e..b905679 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -2781,6 +2781,7 @@ PyString_Format(PyObject *format, PyObject *args) int len; char formatbuf[FORMATBUFLEN]; /* For format{float,int,char}() */ char *fmt_start = fmt; + int argidx_start = argidx; fmt++; if (*fmt == '(') { @@ -2934,6 +2935,7 @@ PyString_Format(PyObject *format, PyObject *args) case 'r': if (PyUnicode_Check(v)) { fmt = fmt_start; + argidx = argidx_start; goto unicode; } if (c == 's') @@ -3098,8 +3100,7 @@ PyString_Format(PyObject *format, PyObject *args) Py_DECREF(args); args_owned = 0; } - /* Fiddle args right (remove the first argidx-1 arguments) */ - --argidx; + /* Fiddle args right (remove the first argidx arguments) */ if (PyTuple_Check(orig_args) && argidx > 0) { PyObject *v; int n = PyTuple_GET_SIZE(orig_args) - argidx; |