Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions Lib/email/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ def header_store_parse(self, name, value):
"""
if hasattr(value, 'name') and value.name.lower() == name.lower():
return (name, value)
if isinstance(value, str) and len(value.splitlines())>1:
# XXX this error message isn't quite right when we use splitlines
# (see issue 22233), but I'm not sure what should happen here.
if (isinstance(value, str) and
linesep_splitter.search(self.header_factory(name, value))
):
raise ValueError("Header values may not contain linefeed "
"or carriage return characters")
"or carriage return characters")
Comment thread
basbloemsaat marked this conversation as resolved.
Resolved
return (name, self.header_factory(name, value))

def header_fetch_parse(self, name, value):
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_email/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ def test_header_store_parse_rejects_newlines(self):
instance.header_store_parse,
'From', 'spam\negg@foo.py')

self.assertRaises(ValueError,
instance.header_store_parse,
'Subject', 'te\nst')

self.assertRaises(ValueError,
instance.header_store_parse,
'Subject', 'A 💩 subject=?UTF-8?Q?=0A?=Bcc: injected@example.com')

if __name__ == '__main__':
unittest.main()
Comment thread
basbloemsaat marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes newlines (and carriage returns) in email headers, both at the end of
Comment thread
basbloemsaat marked this conversation as resolved.
Resolved
the header, and encoded entities that are resolved to newlines and returns