String.decode: Only encode('utf-8') when the decode string is unicode

Closes: Sf#3165718
Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
James McCoy 2011-10-22 14:57:20 -04:00
parent 8f7c4bdf7f
commit 01c8dc7f78

View File

@ -79,7 +79,12 @@ class String(callbacks.Plugin):
<http://docs.python.org/library/codecs.html#standard-encodings>.
"""
try:
irc.reply(text.decode(encoding).encode('utf-8'))
s = text.decode(encoding)
# Not all encodings decode to a unicode object. Only encode those
# that do.
if isinstance(s, unicode):
s = s.encode('utf-8')
irc.reply(s)
except LookupError:
irc.errorInvalid('encoding', encoding)
except binascii.Error: