From 87913c6d660b915a35b4e2ff98f032607699c8a2 Mon Sep 17 00:00:00 2001 From: Florian Best Date: Mon, 1 Jun 2020 04:11:28 +0200 Subject: [PATCH] bpo-40837: Fix email.utils.encode_rfc2231(string, None, None) encode_rfc2231() must not change the returned value if no transformation of the input was done. This is also mentioned in the docstring of that function. Actual behavior: encode_rfc2231('foo bar', None, None) 'foo%20bar' Expected behavior: encode_rfc2231('foo bar', None, None) 'foo bar' --- Lib/email/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/email/utils.py b/Lib/email/utils.py index d4824dc3601b2d..73ab735904cafd 100644 --- a/Lib/email/utils.py +++ b/Lib/email/utils.py @@ -381,9 +381,9 @@ def encode_rfc2231(s, charset=None, language=None): charset is given but not language, the string is encoded using the empty string for language. """ - s = urllib.parse.quote(s, safe='', encoding=charset or 'ascii') if charset is None and language is None: return s + s = urllib.parse.quote(s, safe='', encoding=charset or 'ascii') if language is None: language = '' return "%s'%s'%s" % (charset, language, s)