Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/email/feedparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def close(self):
assert not self._msgstack
# Look for final set of defects
if root.get_content_maintype() == 'multipart' \
and not self._headersonly \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was apparently fixed in #107016 (#106186).

and not root.is_multipart():
defect = errors.MultipartInvariantViolationDefect()
self.policy.handle_defect(root, defect)
Expand Down
2 changes: 1 addition & 1 deletion Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def parse_headers(fp, _class=HTTPMessage):
if line in (b'\r\n', b'\n', b''):
break
hstring = b''.join(headers).decode('iso-8859-1')
return email.parser.Parser(_class=_class).parsestr(hstring)
return email.parser.Parser(_class=_class).parsestr(hstring, headersonly=True)


class HTTPResponse(io.BufferedIOBase):
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_email/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from email.policy import default
from test.test_email import TestEmailBase

class TestFeedParser(TestEmailBase):
def test_multipart_message_with_headers_only(self):
import email.parser
header = 'Content-Type: multipart/related; boundary="==="\r\n\r\n'
msg = email.parser.Parser().parsestr(header, headersonly=True)
self.assertDefectsEqual(msg.defects, [])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed (although it is a more concise test than the one that was committed ;)


class TestCustomMessage(TestEmailBase):

Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ def test_headers_debuglevel(self):
self.assertEqual(lines[1], "header: First: val")
self.assertEqual(lines[2], "header: Second: val")

def test_parse_valid_multipart_header(self):
header = b'Content-Type: multipart/related; boundary="==="\r\n\r\n'
fp = io.BytesIO(header)
message = client.parse_headers(fp)
self.assertListEqual(message.defects, [])

class TransferEncodingTest(TestCase):
expected_body = b"It's just a flesh wound"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes false MultipartInvariantViolationDefects which were triggered when
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't (easily :) tell from these news entries which one is supposed to apply to http and which to email. One of them should go away and the other should clarify which module it applies to.

only headers of a multipart message were parsed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes false StartBoundaryNotFoundDefects which were triggered by
parse_headers not forwarding the headersonly to the email parser.