10000 bpo-36226: Ignore multipart check for headersonly · python/cpython@6dd5999 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6dd5999

Browse files
committed
bpo-36226: Ignore multipart check for headersonly
root cannot be a list if only the headers have been passed on and are being parsed. This fixes false MultipartInvariantViolationDefects
1 parent 1f58f4f commit 6dd5999

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Lib/email/feedparser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def close(self):
189189
assert not self._msgstack
190190
# Look for final set of defects
191191
if root.get_content_maintype() == 'multipart' \
192+
and not self._headersonly \
192193
and not root.is_multipart():
193194
defect = errors.MultipartInvariantViolationDefect()
194195
self.policy.handle_defect(root, defect)

Lib/test/test_email/test_parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
from email.policy import default
66
from test.test_email import TestEmailBase
77

8+
class TestFeedParser(TestEmailBase):
9+
def test_multipart_message_with_headers_only(self):
10+
import email.parser
11+
header = 'Content-Type: multipart/related; boundary="==="\r\n\r\n'
12+
msg = email.parser.Parser().parsestr(header, headersonly=True)
13+
self.assertDefectsEqual(msg.defects, [])
814

915
class TestCustomMessage(TestEmailBase):
1016

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes false MultipartInvariantViolationDefects which were triggered when
2+
only headers of a multipart message were parsed.

0 commit comments

Comments
 (0)
0