mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
#14062: fix BytesParser handling of Header objects
This is a different fix than the 3.2 fix, but the new tests are the same. This also affected smtplib.SMTP.send_message, which calls BytesParser.
This commit is contained in:
commit
8d8f110492
3 changed files with 30 additions and 0 deletions
|
|
@ -3601,6 +3601,30 @@ class Test8BitBytesHandling(unittest.TestCase):
|
|||
g.flatten(msg)
|
||||
self.assertEqual(s.getvalue(), source)
|
||||
|
||||
def test_bytes_generator_b_encoding_linesep(self):
|
||||
# Issue 14062: b encoding was tacking on an extra \n.
|
||||
m = Message()
|
||||
# This has enough non-ascii that it should always end up b encoded.
|
||||
m['Subject'] = Header('žluťoučký kůň')
|
||||
s = BytesIO()
|
||||
g = email.generator.BytesGenerator(s)
|
||||
g.flatten(m, linesep='\r\n')
|
||||
self.assertEqual(
|
||||
s.getvalue(),
|
||||
b'Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=\r\n\r\n')
|
||||
|
||||
def test_generator_b_encoding_linesep(self):
|
||||
# Since this broke in ByteGenerator, test Generator for completeness.
|
||||
m = Message()
|
||||
# This has enough non-ascii that it should always end up b encoded.
|
||||
m['Subject'] = Header('žluťoučký kůň')
|
||||
s = StringIO()
|
||||
g = email.generator.Generator(s)
|
||||
g.flatten(m, linesep='\r\n')
|
||||
self.assertEqual(
|
||||
s.getvalue(),
|
||||
'Subject: =?utf-8?b?xb5sdcWlb3XEjWvDvSBrxa/FiA==?=\r\n\r\n')
|
||||
|
||||
def test_crlf_control_via_policy(self):
|
||||
# msg_26 is crlf terminated
|
||||
with openfile('msg_26.txt', 'rb') as fp:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue