From fb8d0d320a8d9838a4b23e48213d7bd65063c266 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Wed, 14 Apr 2010 10:27:56 -0400 Subject: [PATCH] fix alias bug https://sourceforge.net/tracker/?func=detail&aid=2987147&group_id=58965&atid=489447 add tests for appropriate behavior Signed-off-by: James Vega (cherry picked from commit 8d64d08645319e57f7bee8f9176cae63c67fe1f3) --- plugins/Alias/plugin.py | 22 ++++++++++------------ plugins/Alias/test.py | 6 +++++- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/Alias/plugin.py b/plugins/Alias/plugin.py index 02b66ad07..9021b6809 100644 --- a/plugins/Alias/plugin.py +++ b/plugins/Alias/plugin.py @@ -62,18 +62,18 @@ def getChannel(msg, args=()): raise callbacks.Error, 'Command must be sent in a channel or ' \ 'include a channel in its arguments.' -def getArgs(args, required=1, optional=0): +def getArgs(args, required=1, optional=0, wildcard=0): if len(args) < required: raise callbacks.ArgumentError if len(args) < required + optional: ret = list(args) + ([''] * (required + optional - len(args))) elif len(args) >= required + optional: - ret = list(args[:required + optional - 1]) - ret.append(' '.join(args[required + optional - 1:])) - if len(ret) == 1: - return ret[0] - else: - return ret + if not wildcard: + ret = list(args[:required + optional - 1]) + ret.append(' '.join(args[required + optional - 1:])) + else: + ret = list(args) + return ret class AliasError(Exception): pass @@ -119,11 +119,9 @@ def makeNewAlias(name, alias): channel = getChannel(msg, args) alias = alias.replace('$channel', channel) tokens = callbacks.tokenize(alias) - if not wildcard and biggestDollar or biggestAt: - args = getArgs(args, required=biggestDollar, optional=biggestAt) - # Gotta have a mutable sequence (for replace). - if biggestDollar + biggestAt == 1: # We got a string, no tuple. - args = [args] + if biggestDollar or biggestAt: + args = getArgs(args, required=biggestDollar, optional=biggestAt, + wildcard=wildcard) def regexpReplace(m): idx = int(m.group(1)) return args[idx-1] diff --git a/plugins/Alias/test.py b/plugins/Alias/test.py index a4de21c70..57649dfa6 100644 --- a/plugins/Alias/test.py +++ b/plugins/Alias/test.py @@ -85,7 +85,11 @@ class AliasTestCase(ChannelPluginTestCase): self.assertNotError('alias add swap "echo $2 $1 $*"') self.assertResponse('swap 1 2 3 4 5', '2 1 3 4 5') self.assertError('alias add foo "echo $1 @1 $*"') - + self.assertNotError('alias add moo echo $1 $*') + self.assertError('moo') + self.assertResponse('moo foo', 'foo') + self.assertResponse('moo foo bar', 'foo bar') + def testChannel(self): self.assertNotError('alias add channel echo $channel') self.assertResponse('alias channel', self.channel)