[Python-checkins] r82011 - in python/branches/py3k: Lib/email/feedparser.py Lib/email/test/test_email.py Misc/NEWS

r.david.murray python-checkins at python.org
Wed Jun 16 04:19:41 CEST 2010


Author: r.david.murray
Date: Wed Jun 16 04:19:40 2010
New Revision: 82011

Log:
Merged revisions 81675 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81675 | r.david.murray | 2010-06-03 11:43:20 -0400 (Thu, 03 Jun 2010) | 10 lines
  
  #5610: use \Z not $ so we don't eat extra chars when body part ends with \r\n.
  
  If a body part ended with \r\n, feedparser, using '$' to terminate its
  search for the newline, would match on the \r\n, and think that it needed
  to strip two characters in order to account for the line end before the
  boundary.  That made it chop one too many characters off the end of
  the body part.  Using \Z makes the match correct.
  
  Patch and test by Tony Nelson.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/email/feedparser.py
   python/branches/py3k/Lib/email/test/test_email.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/email/feedparser.py
==============================================================================
--- python/branches/py3k/Lib/email/feedparser.py	(original)
+++ python/branches/py3k/Lib/email/feedparser.py	Wed Jun 16 04:19:40 2010
@@ -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 ":".

Modified: python/branches/py3k/Lib/email/test/test_email.py
==============================================================================
--- python/branches/py3k/Lib/email/test/test_email.py	(original)
+++ python/branches/py3k/Lib/email/test/test_email.py	Wed Jun 16 04:19:40 2010
@@ -2588,6 +2588,24 @@
         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 at 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):

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Wed Jun 16 04:19:40 2010
@@ -432,6 +432,9 @@
 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 #8986: math.erfc was incorrectly raising OverflowError for
   values between -27.3 and -30.0 on some platforms.
 


More information about the Python-checkins mailing list