-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't interpolate byte string with \x00 before replacement identifier #73900
Comments
Python 3.6.0 (default, Mar 3 2017, 00:15:36)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b'a\x00%i' % 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during bytes formatting
>>> b'a%i' % 1
b'a1'
>>> b'a%i\x00' % 1
b'a1\x00' On python3.5, this works in all the scenarios Python 3.5.1 (default, Jan 14 2017, 03:58:20)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b'a\x00%i' % 1
b'a\x001'
>>> b'a%i' % 1
b'a1'
>>> b'a%i\x00' % 1
b'a1\x00' |
Could this be due to using _PyBytesWriter? |
The problem is now _PyBytes_FormatEx uses strchr to sniff %. It should use memchr instead. |
Thanks for the report, Nick! |
I confirm that I introduced the regression with the commit fa7762e: "Issue bpo-25349: Optimize bytes % args using the new private _PyBytesWriter API". Sorry about that, I always forget that str*() functions should not be used in Python since we support embedded null bytes :-/ It seems like only Python 3.6.0 release is affected. "git tag --contains fa7762e" also returns v3.5.2, but I don't understand since I only pushed my change to the 3.6 branch... |
Oh, and thank you for adding new unit tests ;-) Do we need similar unit tests for str%args and str.format()? |
I think no. String is not affected now and its code uses related macros so I don't think it could suffer possible regression. |
Xiang Zhang added the comment:
Regressions are not something "expected", shit happens, all the time. |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: