diff --git a/src/callbacks.py b/src/callbacks.py index 28b1fbabf..e9428c872 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -136,8 +136,8 @@ def _addressed(irc, msg, prefixChars=None, nicks=None, continue except ValueError: # split didn't work. continue - elif whenAddressedByNickAtEnd and lowered.endswith(nick): - rest = payload[:-len(nick)] + elif whenAddressedByNickAtEnd and lowered.rstrip().endswith(nick): + rest = payload.rstrip()[:-len(nick)] possiblePayload = rest.rstrip(' \t,;') if possiblePayload != rest: # There should be some separator between the nick and the diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 33c0d561b..6ce9c1569 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -272,6 +272,12 @@ class FunctionsTestCase(SupyTestCase): self.assertEqual(callbacks.addressed('bar', msg, whenAddressedByNickAtEnd=True), 'baz') + # Test that it still works with trailing whitespace: + msg = ircmsgs.privmsg('#foo', 'baz, bar \t') + self.assertEqual(callbacks.addressed('bar', msg, + whenAddressedByNickAtEnd=True), + 'baz') + def testAddressedPrefixCharsTakePrecedenceOverNickAtEnd(self): irc = getTestIrc()