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
binascii b2a functions accept strings (unicode) as data #48637
Comments
Binascii b2a_xxx functions accept 'binary data' and return ascii-encoded Somewhat surprisingly to me (because the corresponding base64 module Ascii chars almost do
>>> a='aaaa'
>>> c=b.b2a_base64(a)
>>> c
b'YWFhYQ==\n'
>>> d=b.a2b_base64(c)
>>> d
b'aaaa'
But general unicode chars generate nonsense.
>>> a='\u1000'
>>> c=b.b2a_base64(a)
>>> c
b'4YCA\n'
>>> d=b.a2b_base64(c)
>>> d
b'\xe1\x80\x80' I also tried b2a_uu. Is this a bug? |
I vote yes. |
It's not /exactly/ nonsense, it seems to assume an utf8 encoding pass is >>> b'\xe1\x80\x80'.decode('utf8') == '\u1000'
True IMO, while accepting unicode strings instead of bytes for the a2b_xx In other words, it might/should be ok for I think this must be fixed before 3.0 final, and is therefore a release |
Hmm, I obviously meant: [...] In other words, it might/should be ok for |
Here is a patches that fixes the problem. Notice that this affects the email API; base64mime.body_encode now also There are probably more functions that still incorrectly accept strings, |
Martin, the patch looks okay to me. I vote for applying it. |
Committed as r67472. |
Note: 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: