From 2b4c5eb78fb685c530e815e150d4d088b2688a35 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 18 Jul 2023 07:45:26 +0200 Subject: [PATCH] Fix crash when calling .reply(..., action=True) on ReplyIrcProxy instead of on NestedCommandIrcProxy. ReplyIrcProxy._sendReply expects action=True to imply noLengthCheck=True, but only NestedCommandIrcProxy.reply() enforces the latter, not ReplyIrcProxy.reply(). This crash was introduced in 3c1c4a69e9927bcc7265b1d77fd1ab49cb55090e by moving NestedCommandIrcProxy's .reply() to ReplyIrcProxy. --- src/callbacks.py | 3 +++ test/test_callbacks.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/callbacks.py b/src/callbacks.py index e254d0bc3..28b1fbabf 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -733,6 +733,9 @@ class ReplyIrcProxy(RichReplyMethods): kwargs['target'] = kwargs.get('to', None) or msg.args[0] if 'prefixNick' not in kwargs: kwargs['prefixNick'] = self._defaultPrefixNick(msg) + if kwargs.get("action"): + kwargs["prefixNick"] = False + kwargs["noLengthCheck"] = True self._sendReply(s, msg=msg, **kwargs) def __getattr__(self, attr): diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 8420a0263..33c0d561b 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -684,12 +684,26 @@ class PrivmsgTestCase(ChannelPluginTestCase): irc.reply('foo', action=True) irc.reply('bar') # We're going to check that this isn't an action. + def doNotice(self, irc, msg): + irc.reply('foo', action=True) + irc.reply('bar') # We're going to check that this isn't an action. + def testNotActionSecondReply(self): self.irc.addCallback(self.TwoRepliesFirstAction(self.irc)) self.assertAction('testactionreply', 'foo') m = self.getMsg(' ') self.assertFalse(m.args[1].startswith('\x01ACTION')) + def testNotActionSecondReplyNotCommand(self): + """Same as testNotActionSecondReply, but tests ReplyIrcProxy instead of + NestedCommandsIrcProxy.""" + self.irc.addCallback(self.TwoRepliesFirstAction(self.irc)) + self.irc.feedMsg(ircmsgs.notice(self.channel, 'test action reply', + prefix=self.prefix)) + self.assertAction(' ', 'foo') + m = self.getMsg(' ') + self.assertFalse(m.args[1].startswith('\x01ACTION')) + def testEmptyNest(self): try: conf.supybot.reply.whenNotCommand.set('True')