mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
#16564: Fix regression in use of encoders.encode_noop with binary data.
This commit is contained in:
parent
d489c7a0a3
commit
ceaa8b1d75
4 changed files with 28 additions and 0 deletions
|
@ -1438,6 +1438,22 @@ class TestMIMEApplication(unittest.TestCase):
|
|||
eq(msg.get_payload().strip(), '+vv8/f7/')
|
||||
eq(msg.get_payload(decode=True), bytesdata)
|
||||
|
||||
def test_body_with_encode_noop(self):
|
||||
# Issue 16564: This does not produce an RFC valid message, since to be
|
||||
# valid it should have a CTE of binary. But the below works in
|
||||
# Python2, and is documented as working this way.
|
||||
bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
|
||||
msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop)
|
||||
# Treated as a string, this will be invalid code points.
|
||||
self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata))
|
||||
self.assertEqual(msg.get_payload(decode=True), bytesdata)
|
||||
s = BytesIO()
|
||||
g = BytesGenerator(s)
|
||||
g.flatten(msg)
|
||||
wireform = s.getvalue()
|
||||
msg2 = email.message_from_bytes(wireform)
|
||||
self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata))
|
||||
self.assertEqual(msg2.get_payload(decode=True), bytesdata)
|
||||
|
||||
|
||||
# Test the basic MIMEText class
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue