[issue12546] builtin __format__ methods cannot fill with \x00 char

Eric V. Smith report at bugs.python.org
Tue Jul 19 12:17:31 CEST 2011


Eric V. Smith <eric at trueblade.com> added the comment:

I finally got around to reviewing the patch. A couple of comments:

1. There should be some tests for str.__format__, not just str.format. This is really a bug with str.__format__, after all. I can add those.

2. The bigger issue is that the other built in formatters have this same problem.

>>> format(3, '\x00<6')
'3     '
>>> format(3., '\x00<6')
'3.0   '
>>> format('3', '\x00<6')
'3\x00\x00\x00\x00\x00'
>>> format(3+1j, '\x00<6')
'(3+1j)'
[38654 refs]
>>> format(3+1j, '\x00<10')
'(3+1j)    '

I think the fix is basically the same as str.__format__ (but in format_int_or_long_internal, format_float_internal, and format_complex_internal). I tried that and it worked, but I haven't had time to write tests for them. If you (Davide) can do that, great. Otherwise I'll try and grab some time this week.

Changing the subject to match the wider scope of the problem.

----------
stage: commit review -> patch review
title: str.format cannot fill with \x00 char -> builtin __format__ methods cannot fill with \x00 char

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12546>
_______________________________________


More information about the Python-bugs-list mailing list