diff --git a/plugins/String/plugin.py b/plugins/String/plugin.py index bfebd73f0..b68e96497 100644 --- a/plugins/String/plugin.py +++ b/plugins/String/plugin.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2003-2005, Jeremiah Fincher -# Copyright (c) 2008, James Vega +# Copyright (c) 2008-2009, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -29,6 +29,7 @@ ### import types +import binascii import supybot.utils as utils from supybot.commands import * @@ -81,6 +82,10 @@ class String(callbacks.Plugin): irc.reply(text.decode(encoding).encode('utf-8')) except LookupError: irc.errorInvalid('encoding', encoding) + except binascii.Error: + irc.errorInvalid('base64 string', + s='Base64 strings must be a multiple of 4 in ' + 'length, padded with \'=\' if necessary.') decode = wrap(decode, ['something', 'text']) def levenshtein(self, irc, msg, args, s1, s2): diff --git a/plugins/String/test.py b/plugins/String/test.py index a50e4552a..f86d9e38b 100644 --- a/plugins/String/test.py +++ b/plugins/String/test.py @@ -1,5 +1,6 @@ ### # Copyright (c) 2003-2005, Jeremiah Fincher +# Copyright (c) 2009, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -104,6 +105,7 @@ class StringTestCase(PluginTestCase): self.assertNotRegexp('encode aldkfja foobar', 'LookupError') self.assertNotRegexp('decode asdflkj foobar', 'LookupError') self.assertResponse('decode zlib [encode zlib %s]' % s, s) + self.assertRegexp('decode base64 $BCfBg7;9D;R(B', 'padded with') def testRe(self): self.assertResponse('re "m/system time/" [status cpu]', 'system time')