Aka: Remove side effects in everythingReplace and fix crash when evaluating expressions where $* is in the nested command.

This commit is contained in:
Valentin Lorentz 2013-08-11 12:02:00 +02:00
parent 269f22a84b
commit d6223eee9d
2 changed files with 13 additions and 5 deletions

View File

@ -298,19 +298,23 @@ class Aka(callbacks.Plugin):
replace(tokens, lambda s: atRe.sub(regexpReplace, s)) replace(tokens, lambda s: atRe.sub(regexpReplace, s))
if wildcard: if wildcard:
def everythingReplace(tokens): def everythingReplace(tokens):
ret = False
new_tokens = [] new_tokens = []
for (i, token) in enumerate(tokens): for (i, token) in enumerate(tokens):
if isinstance(token, list): if isinstance(token, list):
if everythingReplace(token): (sub_ret, sub_tokens) = everythingReplace(token)
return new_tokens.append(sub_tokens)
if sub_ret:
continue
if token == '$*': if token == '$*':
new_tokens.extend(args) new_tokens.extend(args)
ret = True
else: else:
new_tokens.append( new_tokens.append(
token.replace('$*', ' '.join(args))) token.replace('$*', ' '.join(args)))
tokens[:] = new_tokens ret = True
return False return (ret, new_tokens)
everythingReplace(tokens) (ret, tokens) = everythingReplace(tokens)
self.Proxy(irc, msg, tokens) self.Proxy(irc, msg, tokens)
if biggestDollar and (wildcard or biggestAt): if biggestDollar and (wildcard or biggestAt):
flexargs = _(' at least') flexargs = _(' at least')

View File

@ -97,6 +97,10 @@ class AkaChannelTestCase(ChannelPluginTestCase):
self.assertResponse('moo foo', 'foo') self.assertResponse('moo foo', 'foo')
self.assertResponse('moo foo bar', 'foo bar') self.assertResponse('moo foo bar', 'foo bar')
self.assertNotError('aka add spam "echo [echo $*]"')
self.assertResponse('spam egg', 'egg')
self.assertResponse('spam egg bacon', 'egg bacon')
def testChannel(self): def testChannel(self):
self.assertNotError('aka add channel echo $channel') self.assertNotError('aka add channel echo $channel')
self.assertResponse('aka channel', self.channel) self.assertResponse('aka channel', self.channel)