Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-125648: Add a more descriptive error message when email.message.Message.get_params fails #125755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from
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
3 changes: 3 additions & 0 deletions 3 Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ def decode_params(params):
for name, continuations in rfc2231_params.items():
value = []
extended = False
if len(continuations) > 1 and any(num is None for num, *_ in continuations):
msg = f"Invalid RFC 2231 parameter continuation for '{name}'"
raise ValueError(msg)
# Sort by number
continuations.sort()
# And now append all values in numerical order, converting
Expand Down
10 changes: 10 additions & 0 deletions 10 Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -5757,6 +5757,16 @@ def test_should_not_hang_on_invalid_ew_messages(self):
with self.subTest(m=m):
msg = email.message_from_string(m)

def test_rfc2231_invalid_parameter_continuation(self):
# gh-125648: should raise a ValueError for invalid parameter continuation
m = """\
Content-Type: application/x-foo;
\tname*0="foo";
\tname*="bar"
"""
msg = email.message_from_string(m)
with self.assertRaisesRegex(ValueError, "Invalid RFC 2231 parameter continuation for 'name'"):
msg.get_params()

# Tests to ensure that signed parts of an email are completely preserved, as
# required by RFC1847 section 2.1. Note that these are incomplete, because the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use a more descriptive error message when encountering invalid parameter
continuations in :meth:`email.message.Message.get_params`.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.