diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-06-03 01:58:28 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-06-03 01:58:28 (GMT) |
commit | 850fc85e69b31095769bdb40b3df04e70848eddd (patch) | |
tree | ea53fb862680a60a606669c2d17d2a1b6f261172 /Lib/email/charset.py | |
parent | 775ae4a6f04e17ae361199eef101fe658b4a5e75 (diff) | |
download | cpython-850fc85e69b31095769bdb40b3df04e70848eddd.zip cpython-850fc85e69b31095769bdb40b3df04e70848eddd.tar.gz cpython-850fc85e69b31095769bdb40b3df04e70848eddd.tar.bz2 |
Fix Charset.body_encode to encode to output_charset before calling base64mime.
This means that what gets encoded in base64 is the encoded version of the
unicode payload. This bug was revealed by a forward port of the tests from
Issue 1368247, but the fix was completely different.
Note that the merge is only of the tests, the doc changes were inappropriate
since email5 expects unicode, not bytes. I'm also not convinced that
quopri works correctly in email5, but that's a different issue.
Merged revisions 81658 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81658 | r.david.murray | 2010-06-02 18:03:15 -0400 (Wed, 02 Jun 2010) | 9 lines
#1368247: make set_charset/MIMEText automatically encode unicode _payload.
Fixes (mysterious, to the end user) UnicodeErrors when using utf-8 as
the charset and unicode as the _text argument. Also makes the way in
which unicode gets encoded to quoted printable for other charsets more
sane (it only worked by accident previously). The _payload now is encoded
to the charset.output_charset if it is unicode.
........
Diffstat (limited to 'Lib/email/charset.py')
-rw-r--r-- | Lib/email/charset.py | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Lib/email/charset.py b/Lib/email/charset.py index 9e5ee67..a44b711 100644 --- a/Lib/email/charset.py +++ b/Lib/email/charset.py @@ -377,6 +377,8 @@ class Charset: """ # 7bit/8bit encodings return the string unchanged (module conversions) if self.body_encoding is BASE64: + if isinstance(string, str): + string = string.encode(self.output_charset) return email.base64mime.body_encode(string) elif self.body_encoding is QP: return email.quoprimime.body_encode(string) |