add nick validation to later tell

this avoids plugging the later db with messages for bogus nicks
This commit is contained in:
Daniel Folkinshteyn 2010-04-09 00:45:14 -04:00 committed by Valentin Lorentz
parent a2da24d202
commit fcaa7863fa
2 changed files with 29 additions and 2 deletions

View File

@ -41,7 +41,6 @@ import supybot.callbacks as callbacks
from supybot.i18n import PluginInternationalization, internationalizeDocstring from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Later') _ = PluginInternationalization('Later')
class Later(callbacks.Plugin): class Later(callbacks.Plugin):
"""Used to do things later; currently, it only allows the sending of """Used to do things later; currently, it only allows the sending of
nick-based notes. Do note (haha!) that these notes are *not* private 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.wildcards.append(nick)
self._flushNotes() 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 @internationalizeDocstring
def tell(self, irc, msg, args, nick, text): def tell(self, irc, msg, args, nick, text):
"""<nick> <text> """<nick> <text>
@ -113,8 +131,12 @@ class Later(callbacks.Plugin):
if ircutils.strEqual(nick, irc.nick): if ircutils.strEqual(nick, irc.nick):
irc.error(_('I can\'t send notes to myself.')) irc.error(_('I can\'t send notes to myself.'))
return return
validnick = self._validateNick(nick)
if validnick is False:
irc.error('That is an invalid IRC nick. Please check your input.')
return
try: try:
self._addNote(nick, msg.nick, text) self._addNote(validnick, msg.nick, text)
irc.replySuccess() irc.replySuccess()
except ValueError: except ValueError:
irc.error(_('That person\'s message queue is already full.')) irc.error(_('That person\'s message queue is already full.'))

View File

@ -43,6 +43,11 @@ class LaterTestCase(PluginTestCase):
self.assertNotRegexp('later notes', 'bar.*foo') self.assertNotRegexp('later notes', 'bar.*foo')
self.assertRegexp('later notes', '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: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: