Message298481
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. |
|
Date |
User |
Action |
Args |
2017-07-17 11:33:11 | gdr@garethrees.org | set | recipients:
+ gdr@garethrees.org, zaazbb |
2017-07-17 11:33:11 | gdr@garethrees.org | set | messageid: <1500291191.35.0.913346476165.issue30943@psf.upfronthosting.co.za> |
2017-07-17 11:33:11 | gdr@garethrees.org | link | issue30943 messages |
2017-07-17 11:33:11 | gdr@garethrees.org | create | |
|