From 457de48be460275885ba31b79d791436894e11c2 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 17 Sep 2003 08:07:24 +0000 Subject: [PATCH] Made sure no information is leaked with last being able to return private messages. --- src/MiscCommands.py | 10 +++++++--- test/test_MiscCommands.py | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/MiscCommands.py b/src/MiscCommands.py index 3d1072b65..098ebdb13 100755 --- a/src/MiscCommands.py +++ b/src/MiscCommands.py @@ -41,6 +41,7 @@ import getopt import pprint import smtplib import textwrap +from itertools import ifilter import conf import debug @@ -311,6 +312,11 @@ class MiscCommands(callbacks.Privmsg): except IndexError: 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): """[--{from,in,to,with,regexp,fancy}] @@ -346,12 +352,10 @@ class MiscCommands(callbacks.Privmsg): return predicates.append(lambda m: r.search(m.args[1])) first = True - for m in reviter(irc.state.history): + for m in ifilter(self._validLastMsg, reviter(irc.state.history)): if first: first = False continue - if not m.prefix or m.command != 'PRIVMSG': - continue for predicate in predicates: if not predicate(m): break diff --git a/test/test_MiscCommands.py b/test/test_MiscCommands.py index 4a2725d6a..349909d1f 100644 --- a/test/test_MiscCommands.py +++ b/test/test_MiscCommands.py @@ -31,7 +31,7 @@ from test import * -class MiscCommandsTestCase(PluginTestCase, PluginDocumentation): +class MiscCommandsTestCase(ChannelPluginTestCase, PluginDocumentation): plugins = ('MiscCommands', 'Utilities', 'ChannelDB') def testReplyWhenNotCommand(self): conf.replyWhenNotCommand = True @@ -95,9 +95,9 @@ class MiscCommandsTestCase(PluginTestCase, PluginDocumentation): def testLast(self): self.feedMsg('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 --regexp m/\s+/', 'last --with foo') + self.assertRegexp('last --regexp m/\s+/', 'last --with foo') self.assertResponse('last --regexp m/bar/', 'foo bar baz') def testMore(self):