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'
This commit is contained in:
Florian Best 2020-06-01 04:11:28 +02:00
parent 2f172d8f15
commit 6e67becb7b
1 changed files with 1 additions and 1 deletions

View File

@ -243,9 +243,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)