mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 12:12:54 +01:00
MessageParser: Fix crash (and unexpected behavior) when matching backslashes
Closes GH-1497.
This commit is contained in:
parent
068488c546
commit
2d5c80736d
@ -183,7 +183,9 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
self._updateRank(irc.network, channel, regexp)
|
||||
for (i, j) in enumerate(match.groups()):
|
||||
if match.group(i+1) is not None:
|
||||
thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction)
|
||||
# Need a lambda to prevent re.sub from
|
||||
# interpreting backslashes in the replacement
|
||||
thisaction = re.sub(r'\$' + str(i+1), lambda _: match.group(i+1), thisaction)
|
||||
actions.append(thisaction)
|
||||
if max_triggers != 0 and max_triggers == len(actions):
|
||||
break
|
||||
|
@ -91,6 +91,13 @@ class MessageParserTestCase(ChannelPluginTestCase):
|
||||
self.feedMsg('test')
|
||||
self.assertResponse(' ', 'Error: No closing quotation')
|
||||
|
||||
def testMatchedBackslashes(self):
|
||||
# Makes sure backslashes in matched arguments are not interpreted
|
||||
# (re.sub interprets them in the repl argument for some reason...)
|
||||
self.assertNotError(r'messageparser add test(.*)test "echo $1"')
|
||||
self.feedMsg(r'testhello\xhellotest')
|
||||
self.assertResponse(' ', r'hello\xhello')
|
||||
|
||||
def testShow(self):
|
||||
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
|
||||
self.assertRegexp('messageparser show "nostuff"', 'there is no such regexp trigger')
|
||||
|
Loading…
Reference in New Issue
Block a user