mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 21:29:24 +01:00
add nick validation to later tell
this avoids plugging the later db with messages for bogus nicks
This commit is contained in:
parent
01c8f3445a
commit
2125e6db8e
@ -39,7 +39,6 @@ import supybot.ircmsgs as ircmsgs
|
||||
import supybot.ircutils as ircutils
|
||||
import supybot.callbacks as callbacks
|
||||
|
||||
|
||||
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
|
||||
@ -100,6 +99,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
|
||||
|
||||
def tell(self, irc, msg, args, nick, text):
|
||||
"""<nick> <text>
|
||||
|
||||
@ -110,8 +128,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.')
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user