summaryrefslogtreecommitdiffstats
path: root/Lib/email/utils.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-06-08 07:38:39 (GMT)
committerGitHub <noreply@github.com>2025-06-08 07:38:39 (GMT)
commit85efa77e35661a077390caba12f2f2c9c26f86a5 (patch)
treecb54175b48135ae10b89f79e01d5d427c9426624 /Lib/email/utils.py
parentef539654e682cc451ea68fa366a16e9020df89b8 (diff)
downloadcpython-85efa77e35661a077390caba12f2f2c9c26f86a5.zip
cpython-85efa77e35661a077390caba12f2f2c9c26f86a5.tar.gz
cpython-85efa77e35661a077390caba12f2f2c9c26f86a5.tar.bz2
[3.14] gh-134151 Fix `TypeError` in `email.utils.decode_params` when sorting RFC 2231 continuations (GH-134687) (#135247)
gh-134151 Fix `TypeError` in `email.utils.decode_params` when sorting RFC 2231 continuations (GH-134687) - Fix sorting logic in `email.utils.decode_params` to handle None values. - Update tests for RFC 2231 continuation sorting. (cherry picked from commit bcb6b45cb86a2f9f65b6c41f27c36059ba86a50b) Co-authored-by: Jiucheng(Oliver) <git.jiucheng@gmail.com>
Diffstat (limited to 'Lib/email/utils.py')
-rw-r--r--Lib/email/utils.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/email/utils.py b/Lib/email/utils.py
index 7eab74d..3de1f0d 100644
--- a/Lib/email/utils.py
+++ b/Lib/email/utils.py
@@ -417,8 +417,14 @@ 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 0 if there is no 0,
+ # and ignore it if there is already a 0.
+ has_zero = any(x[0] == 0 for x in continuations)
+ if has_zero:
+ continuations = [x for x in continuations if x[0] is not None]
+ else:
+ continuations = [(x[0] or 0, x[1], x[2]) for x in continuations]
+ continuations.sort(key=lambda x: 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