Incorrect behavior in str.format() method when padding with '\x00'
Hi all, Is there any particularly reason for the following behavior on both 2.7.6 and 3.4.0 ?
"{:\x00<5}".format(2) '2 '
"{:\x20<5}".format(2)
'2 '
"{:\x01<5}".format(2)
'2\x01\x01\x01\x01'
"{:\x00<5}".format(2) == "{:\x20<5}".format(2)
True
The docs say "If a valid *align* value is specified, it can be preceded by a *fill* character that can be any character and defaults to a space if omitted," so I'm inclined to call this a good old fashioned bug. -- John Tyree Scientific Software Developer Enthought, Inc. www.enthought.com
On 04/02/2014 04:08 PM, John Tyree wrote:
Hi all,
Is there any particularly reason for the following behavior on both 2.7.6 and 3.4.0 ?
>>> "{:\x00<5}".format(2) '2 ' >>> "{:\x20<5}".format(2)
'2 ' >>> "{:\x01<5}".format(2)
'2\x01\x01\x01\x01' >>> "{:\x00<5}".format(2) == "{:\x20<5}".format(2)
True
The docs say "If a valid /align/ value is specified, it can be preceded by a /fill/ character that can be any character and defaults to a space if omitted," so I'm inclined to call this a good old fashioned bug.
I'd say it's a bug. Please open a bug, assign it to me (eric.smith), and I'll comment on it there. Eric.
On Thu, 03 Apr 2014 11:20:20 -0400, "Eric V. Smith" <eric@trueblade.com> wrote:
On 04/02/2014 04:08 PM, John Tyree wrote:
Hi all,
Is there any particularly reason for the following behavior on both 2.7.6 and 3.4.0 ?
>>> "{:\x00<5}".format(2) '2 ' >>> "{:\x20<5}".format(2)
'2 ' >>> "{:\x01<5}".format(2)
'2\x01\x01\x01\x01' >>> "{:\x00<5}".format(2) == "{:\x20<5}".format(2)
True
The docs say "If a valid /align/ value is specified, it can be preceded by a /fill/ character that can be any character and defaults to a space if omitted," so I'm inclined to call this a good old fashioned bug.
I'd say it's a bug. Please open a bug, assign it to me (eric.smith), and I'll comment on it there.
There is an existing bug report (assigned to you :), with a partial patch: http://bugs.python.org/issue12546 --David
On 04/03/2014 11:37 AM, R. David Murray wrote:
On Thu, 03 Apr 2014 11:20:20 -0400, "Eric V. Smith" <eric@trueblade.com> wrote:
On 04/02/2014 04:08 PM, John Tyree wrote:
Hi all,
Is there any particularly reason for the following behavior on both 2.7.6 and 3.4.0 ?
>>> "{:\x00<5}".format(2) '2 ' >>> "{:\x20<5}".format(2)
'2 ' >>> "{:\x01<5}".format(2)
'2\x01\x01\x01\x01' >>> "{:\x00<5}".format(2) == "{:\x20<5}".format(2)
True
The docs say "If a valid /align/ value is specified, it can be preceded by a /fill/ character that can be any character and defaults to a space if omitted," so I'm inclined to call this a good old fashioned bug.
I'd say it's a bug. Please open a bug, assign it to me (eric.smith), and I'll comment on it there.
There is an existing bug report (assigned to you :), with a partial patch: http://bugs.python.org/issue12546
Heh. I'll add this to my list of things to do at PyCon sprints. Eric.
On 2014-04-03 16:20, Eric V. Smith wrote:
On 04/02/2014 04:08 PM, John Tyree wrote:
Hi all,
Is there any particularly reason for the following behavior on both 2.7.6 and 3.4.0 ?
>>> "{:\x00<5}".format(2) '2 ' >>> "{:\x20<5}".format(2)
'2 ' >>> "{:\x01<5}".format(2)
'2\x01\x01\x01\x01' >>> "{:\x00<5}".format(2) == "{:\x20<5}".format(2)
True
The docs say "If a valid /align/ value is specified, it can be preceded by a /fill/ character that can be any character and defaults to a space if omitted," so I'm inclined to call this a good old fashioned bug.
I'd say it's a bug. Please open a bug, assign it to me (eric.smith), and I'll comment on it there.
I'd agree. It looks like '\x00' is being confused with a NUL terminator in the C code. I've seen such a thing before (now fixed).
On 04/03/2014 11:49 AM, MRAB wrote:
On 2014-04-03 16:20, Eric V. Smith wrote:
On 04/02/2014 04:08 PM, John Tyree wrote:
Hi all,
Is there any particularly reason for the following behavior on both 2.7.6 and 3.4.0 ?
>>> "{:\x00<5}".format(2) '2 ' >>> "{:\x20<5}".format(2)
'2 ' >>> "{:\x01<5}".format(2)
'2\x01\x01\x01\x01' >>> "{:\x00<5}".format(2) == "{:\x20<5}".format(2)
True
The docs say "If a valid /align/ value is specified, it can be preceded by a /fill/ character that can be any character and defaults to a space if omitted," so I'm inclined to call this a good old fashioned bug.
I'd say it's a bug. Please open a bug, assign it to me (eric.smith), and I'll comment on it there.
I'd agree. It looks like '\x00' is being confused with a NUL terminator in the C code. I've seen such a thing before (now fixed).
Now that I recall the other issue (that I should have fixed already, but let drop), it's because 0 is used as a flag to mean "use the default". Eric.
participants (4)
-
Eric V. Smith
-
John Tyree
-
MRAB
-
R. David Murray