From 50e4b6baf1e4e8f63d45a4ee9b7a2fd9a4833b3f Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 22 Oct 2011 14:57:20 -0400 Subject: [PATCH] String.decode: Only encode('utf-8') when the decode string is unicode Closes: Sf#3165718 Signed-off-by: James McCoy (cherry picked from commit 01c8dc7f78352c6e11b75b67efa0f816e0881702) Signed-off-by: Daniel Folkinshteyn --- plugins/String/plugin.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/String/plugin.py b/plugins/String/plugin.py index 96da6855f..93f8942e8 100644 --- a/plugins/String/plugin.py +++ b/plugins/String/plugin.py @@ -81,7 +81,12 @@ class String(callbacks.Plugin): . """ 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: