Seen: Anchor nick regexp to ensure valid match.

When searching for 'st*ke', 'stryker' would incorrectly match, 'stryke' would
be added to the nick set and the subsequent lookup would cause a KeyError.
This is fixed both by anchoring the regexp ('^st.*ke$' instead of 'st.*ke')
and adding searchNick to the nick set instead of the string that matched the
pattern.

Closes: Sf#3377381

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
James Vega 2011-08-02 22:19:47 -04:00
parent b0e595fbd2
commit 0cd4939678

View File

@ -1,6 +1,6 @@
### ###
# Copyright (c) 2002-2004, Jeremiah Fincher # Copyright (c) 2002-2004, Jeremiah Fincher
# Copyright (c) 2010, James Vega # Copyright (c) 2010-2011, James Vega
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -66,7 +66,7 @@ class SeenDB(plugins.ChannelUserDB):
def seenWildcard(self, channel, nick): def seenWildcard(self, channel, nick):
nicks = ircutils.IrcSet() nicks = ircutils.IrcSet()
nickRe = re.compile('.*'.join(nick.split('*')), re.I) nickRe = re.compile('^%s$' % '.*'.join(nick.split('*')), re.I)
for (searchChan, searchNick) in self.keys(): for (searchChan, searchNick) in self.keys():
#print 'chan: %s ... nick: %s' % (searchChan, searchNick) #print 'chan: %s ... nick: %s' % (searchChan, searchNick)
if isinstance(searchNick, int): if isinstance(searchNick, int):
@ -75,11 +75,8 @@ class SeenDB(plugins.ChannelUserDB):
# are keyed by nick-string # are keyed by nick-string
continue continue
if ircutils.strEqual(searchChan, channel): if ircutils.strEqual(searchChan, channel):
try: if nickRe.search(searchNick) is not None:
s = nickRe.match(searchNick).group() nicks.add(searchNick)
except AttributeError:
continue
nicks.add(s)
L = [[nick, self.seen(channel, nick)] for nick in nicks] L = [[nick, self.seen(channel, nick)] for nick in nicks]
def negativeTime(x): def negativeTime(x):
return -x[1][0] return -x[1][0]