]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix for SF bug #1072623. When the last line of the input string does not end
authorBarry Warsaw <barry@python.org>
Sun, 28 Nov 2004 00:21:42 +0000 (00:21 +0000)
committerBarry Warsaw <barry@python.org>
Sun, 28 Nov 2004 00:21:42 +0000 (00:21 +0000)
in a newline, and it's an end boundary, the FeedParser wasn't recognizing it
as such.  Tweak the regexp to make the ending linesep optional.

For grins, clear self._partial when closing the BufferedSubFile.

Added a test case.

Lib/email/FeedParser.py
Lib/email/test/test_email.py

index 1d6e3dd1cf160bfd7b7ce6b4e4418b3f466ccf5c..690b7c2866df84d160432e17fb50b2f75d33d3a7 100644 (file)
@@ -62,6 +62,7 @@ class BufferedSubFile(object):
     def close(self):
         # Don't forget any trailing partial line.
         self._lines.append(self._partial)
+        self._partial = ''
         self._closed = True
 
     def readline(self):
@@ -279,7 +280,7 @@ class FeedParser:
             separator = '--' + boundary
             boundaryre = re.compile(
                 '(?P<sep>' + re.escape(separator) +
-                r')(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)$')
+                r')(?P<end>--)?(?P<ws>[ \t]*)(?P<linesep>\r\n|\r|\n)?$')
             capturing_preamble = True
             preamble = []
             linesep = False
index 2fcd859ab88231dd521b94670ea1baf0d8347b97..c62044245875c3211ddff8b4b2a40e0abef65ee5 100644 (file)
@@ -1351,6 +1351,20 @@ Content-Type: text/plain
         eq(msg.get_boundary(), '    XXXX')
         eq(len(msg.get_payload()), 2)
 
+    def test_boundary_without_trailing_newline(self):
+        m = Parser().parsestr("""\
+Content-Type: multipart/mixed; boundary="===============0012394164=="
+MIME-Version: 1.0
+
+--===============0012394164==
+Content-Type: image/file1.jpg
+MIME-Version: 1.0
+Content-Transfer-Encoding: base64
+
+YXNkZg==
+--===============0012394164==--""")
+        self.assertEquals(m.get_payload(0).get_payload(), 'YXNkZg==')
+
 
 \f
 # Test some badly formatted messages