diff --git a/plugins/Later/plugin.py b/plugins/Later/plugin.py index b382559af..6c423b4e6 100644 --- a/plugins/Later/plugin.py +++ b/plugins/Later/plugin.py @@ -41,7 +41,6 @@ import supybot.callbacks as callbacks from supybot.i18n import PluginInternationalization, internationalizeDocstring _ = PluginInternationalization('Later') - class Later(callbacks.Plugin): """Used to do things later; currently, it only allows the sending of nick-based notes. Do note (haha!) that these notes are *not* private @@ -102,6 +101,25 @@ class Later(callbacks.Plugin): self.wildcards.append(nick) self._flushNotes() + def _validateNick(self, nick): + """Validate nick according to the IRC RFC 2812 spec. + + Reference: http://tools.ietf.org/rfcmarkup?doc=2812#section-2.3.1 + + Some irc clients' tab-completion feature appends 'address' characters + to nick, such as ':' or ','. We try correcting for that by trimming + a char off the end. + + If nick incorrigibly invalid, return False, otherwise, + return (possibly trimmed) nick. + """ + if not ircutils.isNick(nick, strictRfc=True): + if not ircutils.isNick(nick[:-1], strictRfc=True): + return False + else: + return nick[:-1] + return nick + @internationalizeDocstring def tell(self, irc, msg, args, nick, text): """ @@ -113,8 +131,12 @@ class Later(callbacks.Plugin): if ircutils.strEqual(nick, irc.nick): irc.error(_('I can\'t send notes to myself.')) return + validnick = self._validateNick(nick) + if validnick is False: + irc.error('That is an invalid IRC nick. Please check your input.') + return try: - self._addNote(nick, msg.nick, text) + self._addNote(validnick, msg.nick, text) irc.replySuccess() except ValueError: irc.error(_('That person\'s message queue is already full.')) diff --git a/plugins/Later/test.py b/plugins/Later/test.py index dc3a95069..d91070620 100644 --- a/plugins/Later/test.py +++ b/plugins/Later/test.py @@ -43,6 +43,11 @@ class LaterTestCase(PluginTestCase): self.assertNotRegexp('later notes', 'bar.*foo') self.assertRegexp('later notes', 'foo') + def testNickValidation(self): + self.assertError('later tell 1foo bar') + self.assertError('later tell foo$moo zoob') + self.assertNotError('later tell foo: baz') + self.assertRegexp('later notes', 'foo\.') # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: