mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-03 16:39:25 +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
a2da24d202
commit
fcaa7863fa
@ -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):
|
||||
"""<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.'))
|
||||
|
@ -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