1. Armin Rigo
  2. cpython-withatomic

Commits

Barry Warsaw  committed 7a5a56a

Fix for SF bug #1072623. When the last line of the input string does not end
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.

  • Participants
  • Parent commits 5be31a2
  • Branches legacy-trunk

Comments (0)

Files changed (2)

File Lib/email/FeedParser.py

View file
  • Ignore whitespace
     def close(self):
         # Don't forget any trailing partial line.
         self._lines.append(self._partial)
+        self._partial = ''
         self._closed = True
 
     def readline(self):
             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

File Lib/email/test/test_email.py

View file
  • Ignore whitespace
         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==')
+
 
 
 # Test some badly formatted messages