diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py index afb02b32b24..163fadafd4a 100644 --- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -28,7 +28,7 @@ NLCRE = re.compile('\r\n|\r|\n') NLCRE_bol = re.compile('(\r\n|\r|\n)') -NLCRE_eol = re.compile('(\r\n|\r|\n)$') +NLCRE_eol = re.compile('(\r\n|\r|\n)\Z') NLCRE_crack = re.compile('(\r\n|\r|\n)') # RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character # except controls, SP, and ":". diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py index 7d0107936cc..94eec86bde7 100644 --- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -2610,6 +2610,24 @@ def test_rfc2822_one_character_header(self): eq(headers, ['A', 'B', 'CC']) eq(msg.get_payload(), 'body') + def test_CRLFLF_at_end_of_part(self): + # issue 5610: feedparser should not eat two chars from body part ending + # with "\r\n\n". + m = ( + "From: foo@bar.com\n" + "To: baz\n" + "Mime-Version: 1.0\n" + "Content-Type: multipart/mixed; boundary=BOUNDARY\n" + "\n" + "--BOUNDARY\n" + "Content-Type: text/plain\n" + "\n" + "body ending with CRLF newline\r\n" + "\n" + "--BOUNDARY--\n" + ) + msg = email.message_from_string(m) + self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n')) class TestBase64(unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS index 25b265b6c6e..81891c15a10 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -46,6 +46,9 @@ C-API Library ------- +- Issue #5610: feedparser no longer eats extra characters at the end of + a body part if the body part ends with a \r\n. + - Issue #8833: tarfile created hard link entries with a size field != 0 by mistake.