This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: % formatting fails to find formatting code in bytes type after a null byte
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: can't interpolate byte string with \x00 before replacement identifier
View: 29714
Assigned To: Nosy List: boramalper, xiang.zhang
Priority: normal Keywords:

Created on 2017-03-28 14:37 by boramalper, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg290724 - (view) Author: Mert Bora Alper (boramalper) * Date: 2017-03-28 14:37
Hello,

In Python 3.6.0, % formatting fails to find formatting code after a null byte in bytes type.

Example:
    >>> "%s_\x00%s" % ("hello", "world")
    'hello_\x00world'
    >>> b"%s_\x00%s" % (b"hello", b"world")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: not all arguments converted during bytes formatting

In contrast, the exact same code works as expected in Python 3.5:

    >>> "%s_\x00%s" % ("hello", "world")
    'hello_\x00world'
    >>> b"%s_\x00%s" % (b"hello", b"world")
    b'hello_\x00world'

I used Python 3.6.0 that I installed using pyenv 1.0.8 on Kubuntu 16.04 x86_64.
msg290726 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-03-28 14:43
Yes, this is a regression in 3.6.0 and it has been fixed in #29714 for 3.6.1. Try the new version. :-)
msg290727 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-03-28 14:47
Sorry, the fix is for 3.6.2 so 3.6.1 would still suffer from it. :-(
History
Date User Action Args
2022-04-11 14:58:44adminsetgithub: 74120
2017-03-28 14:47:13xiang.zhangsetmessages: + msg290727
2017-03-28 14:43:07xiang.zhangsetstatus: open -> closed

superseder: can't interpolate byte string with \x00 before replacement identifier

nosy: + xiang.zhang
messages: + msg290726
resolution: duplicate
stage: resolved
2017-03-28 14:39:33boramalpersetcomponents: + Interpreter Core
2017-03-28 14:37:41boramalpercreate