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
2 changes: 1 addition & 1 deletion Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def encode_rfc2231(s, charset=None, language=None):
return "%s'%s'%s" % (charset, language, s)


rfc2231_continuation = re.compile(r'^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$',
rfc2231_continuation = re.compile(r'^(?P<name>[\w-]+)\*((?P<num>[0-9]+)\*?)?$',

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.

If we're going to go to the trouble of fixing this, we should make it conform fully to the RFC. Are there any printable characters other than - that are not in specials and also not in \w? Hopefully there aren't any characters recognized by \w that shouldn't be valid in parameter names, because changing that would be backward incompatible.

re.ASCII)

def decode_params(params):
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ def test_continuation_sorting_part_order(self):
filename = msg.get_filename()
self.assertEqual(filename, 'foo bar.txt')

def test_continuation_with_hyphenated_name(self):
# gh-130110: parameter names containing hyphens were not recognized
# as RFC 2231 continuations and were left undecoded.
msg = email.message_from_string(
"Content-Disposition: attachment; "
"file-name*0*=\"utf-8''start\"; "
"file-name*1*=\"-middle-\"; "
"file-name*2*=\"end\"\n"
)
value = msg.get_param('file-name', header='content-disposition')
self.assertEqual(value, ('utf-8', '', 'start-middle-end'))

def test_sorting_no_continuations(self):
msg = email.message_from_string(
"Content-Disposition: attachment; "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:meth:`email.utils.decode_params` (and the parameter parsing it backs) now
correctly decodes :rfc:`2231` continuation parameter names that contain
hyphens, such as ``file-name*0*``.
Loading