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.

Author gdr@garethrees.org
Recipients gdr@garethrees.org, zaazbb
Date 2017-07-17.11:33:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1500291191.35.0.913346476165.issue30943@psf.upfronthosting.co.za>
In-reply-to
Content
Test case minimization:

    Python 3.6.1 (default, Apr 24 2017, 06:18:27) 
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> b'a\x00%(a)s' % {b'a': b'a'}
    b'a\x00%(a)s'

It seems that all formatting operations after a zero byte are ignored. This is because the code for parsing the format string (in _PyBytes_FormatEx in Objects/bytesobject.c) uses the following approach to find the next % character:

    while (--fmtcnt >= 0) {
        if (*fmt != '%') {
            Py_ssize_t len;
            char *pos;
            pos = strchr(fmt + 1, '%');

But strchr uses the C notion of strings, which are terminated by a zero byte.
History
Date User Action Args
2017-07-17 11:33:11gdr@garethrees.orgsetrecipients: + gdr@garethrees.org, zaazbb
2017-07-17 11:33:11gdr@garethrees.orgsetmessageid: <1500291191.35.0.913346476165.issue30943@psf.upfronthosting.co.za>
2017-07-17 11:33:11gdr@garethrees.orglinkissue30943 messages
2017-07-17 11:33:11gdr@garethrees.orgcreate