mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
#15249: Mangle From lines correctly when body contains invalid bytes.
Fix by Colin Su. Test by me, based on a test written by Petri Lehtinen.
This commit is contained in:
parent
f2b34b8b96
commit
638d40b433
4 changed files with 21 additions and 1 deletions
|
|
@ -20,7 +20,7 @@ import email
|
|||
from email.charset import Charset
|
||||
from email.header import Header, decode_header, make_header
|
||||
from email.parser import Parser, HeaderParser
|
||||
from email.generator import Generator, DecodedGenerator
|
||||
from email.generator import Generator, DecodedGenerator, BytesGenerator
|
||||
from email.message import Message
|
||||
from email.mime.application import MIMEApplication
|
||||
from email.mime.audio import MIMEAudio
|
||||
|
|
@ -1298,6 +1298,20 @@ Blah blah blah
|
|||
self.assertEqual(len([1 for x in s.getvalue().split('\n')
|
||||
if x.startswith('>From ')]), 2)
|
||||
|
||||
def test_mangled_from_with_bad_bytes(self):
|
||||
source = textwrap.dedent("""\
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: 8bit
|
||||
From: aaa@bbb.org
|
||||
|
||||
""").encode('utf-8')
|
||||
msg = email.message_from_bytes(source + b'From R\xc3\xb6lli\n')
|
||||
b = BytesIO()
|
||||
g = BytesGenerator(b, mangle_from_=True)
|
||||
g.flatten(msg)
|
||||
self.assertEqual(b.getvalue(), source + b'>From R\xc3\xb6lli\n')
|
||||
|
||||
|
||||
# Test the basic MIMEAudio class
|
||||
class TestMIMEAudio(unittest.TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue