Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions Lib/email/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ def decode_params(params):
for name, continuations in rfc2231_params.items():
value = []
extended = False
# Sort by number
continuations.sort()
# Sort by number, treating None as greater than any integer.
# In Python 3, None cannot be compared to int, so use a tuple key.
continuations.sort(key=lambda x: (x[0] is None, x[0]))
# And now append all values in numerical order, converting
# %-encodings for the encoded segments. If any of the
# continuation names ends in a *, then the entire string, after
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ def test_bad_param(self):
msg = email.message_from_string("Content-Type: blarg; baz; boo\n")
self.assertEqual(msg.get_param('baz'), '')

def test_continuation_sorting_no_typeerror(self):
msg = email.message_from_string(
"Content-Disposition: attachment; "
"filename*=\"ignored\"; "
"filename*0*=\"utf-8''foo%20\"; "
"filename*1*=\"bar.txt\"\n"
)
filename = msg.get_filename()
self.assertEqual(filename, 'foo bar.txtignored')

def test_missing_filename(self):
msg = email.message_from_string("From: foo\n")
self.assertEqual(msg.get_filename(), None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`email`: Fix TypeError in email.utils.decode_params() when sorting RFC
2231 continuations on Python 3.
Loading