Made sure no information is leaked with last being able to return private messages.

This commit is contained in:
Jeremy Fincher 2003-09-17 08:07:24 +00:00
parent 71bba5d28c
commit 457de48be4
2 changed files with 10 additions and 6 deletions

View File

@ -41,6 +41,7 @@ import getopt
import pprint import pprint
import smtplib import smtplib
import textwrap import textwrap
from itertools import ifilter
import conf import conf
import debug import debug
@ -311,6 +312,11 @@ class MiscCommands(callbacks.Privmsg):
except IndexError: except IndexError:
irc.error(msg, 'That\'s all, there is no more.') irc.error(msg, 'That\'s all, there is no more.')
def _validLastMsg(self, msg):
return msg.prefix and \
msg.command == 'PRIVMSG' and \
ircutils.isChannel(msg.args[0])
def last(self, irc, msg, args): def last(self, irc, msg, args):
"""[--{from,in,to,with,regexp,fancy}] <args> """[--{from,in,to,with,regexp,fancy}] <args>
@ -346,12 +352,10 @@ class MiscCommands(callbacks.Privmsg):
return return
predicates.append(lambda m: r.search(m.args[1])) predicates.append(lambda m: r.search(m.args[1]))
first = True first = True
for m in reviter(irc.state.history): for m in ifilter(self._validLastMsg, reviter(irc.state.history)):
if first: if first:
first = False first = False
continue continue
if not m.prefix or m.command != 'PRIVMSG':
continue
for predicate in predicates: for predicate in predicates:
if not predicate(m): if not predicate(m):
break break

View File

@ -31,7 +31,7 @@
from test import * from test import *
class MiscCommandsTestCase(PluginTestCase, PluginDocumentation): class MiscCommandsTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('MiscCommands', 'Utilities', 'ChannelDB') plugins = ('MiscCommands', 'Utilities', 'ChannelDB')
def testReplyWhenNotCommand(self): def testReplyWhenNotCommand(self):
conf.replyWhenNotCommand = True conf.replyWhenNotCommand = True
@ -95,9 +95,9 @@ class MiscCommandsTestCase(PluginTestCase, PluginDocumentation):
def testLast(self): def testLast(self):
self.feedMsg('foo bar baz') self.feedMsg('foo bar baz')
self.assertResponse('last', 'foo bar baz') self.assertResponse('last', 'foo bar baz')
self.assertResponse('last', 'last') self.assertRegexp('last', 'last')
self.assertResponse('last --with foo', 'foo bar baz') self.assertResponse('last --with foo', 'foo bar baz')
self.assertResponse('last --regexp m/\s+/', 'last --with foo') self.assertRegexp('last --regexp m/\s+/', 'last --with foo')
self.assertResponse('last --regexp m/bar/', 'foo bar baz') self.assertResponse('last --regexp m/bar/', 'foo bar baz')
def testMore(self): def testMore(self):