8000 bpo-36226: Fix email parsing more than headers · python/cpython@bb9dd1b · GitHub
[go: up one dir, main page]

Skip to content

Commit bb9dd1b

Browse files
committed
bpo-36226: Fix email parsing more than headers
Currently parse_headers only gives headers to the parser. For the parser to correctly handle this case, it also needs to set headersonly=True This fixes false StartBoundaryNotFoundDefects
1 parent 6dd5999 commit bb9dd1b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Lib/http/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def parse_headers(fp, _class=HTTPMessage):
211211
if line in (b'\r\n', b'\n', b''):
212212
break
213213
hstring = b''.join(headers).decode('iso-8859-1')
214-
return email.parser.Parser(_class=_class).parsestr(hstring)
214+
return email.parser.Parser(_class=_class).parsestr(hstring, headersonly=True)
215215

216216

217217
class HTTPResponse(io.BufferedIOBase):

Lib/test/test_httplib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ def test_headers_debuglevel(self):
359359
self.assertEqual(lines[1], "header: First: val")
360360
self.assertEqual(lines[2], "header: Second: val")
361361

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

363368
class TransferEncodingTest(TestCase):
364369
expected_body = b"It's just a flesh wound"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes false StartBoundaryNotFoundDefects which were triggered by
2+
parse_headers not forwarding the headersonly to the email parser.

0 commit comments

Comments
 (0)
0