diff --git a/irctokens/line.py b/irctokens/line.py index 55bfb12..a065c4f 100644 --- a/irctokens/line.py +++ b/irctokens/line.py @@ -109,7 +109,10 @@ def tokenise( else: dline = line - if "\x00" in dline: - dline, _ = dline.split("\x00", 1) + for badchar in set(dline) & {"\x00", "\r", "\n"}: + badindex = dline.find(badchar) + if not badindex == -1: + # truncate before this bad character + dline = dline[:badindex] return _tokenise(dline) diff --git a/test/tokenise.py b/test/tokenise.py index 5de1370..eabb901 100644 --- a/test/tokenise.py +++ b/test/tokenise.py @@ -71,12 +71,22 @@ class TokenTestAll(unittest.TestCase): self.assertEqual(line.command, "PRIVMSG") self.assertEqual(line.params, ["#channel", "hello world"]) -class TokenTestNul(unittest.TestCase): - def test(self): +class TokenTestTruncate(unittest.TestCase): + def test_null(self): line = irctokens.tokenise( ":nick!user@host PRIVMSG #channel :hello\x00 world") self.assertEqual(line.params, ["#channel", "hello"]) + def test_cr(self): + line = irctokens.tokenise( + ":nick!user@host PRIVMSG #channel :hello\r world") + self.assertEqual(line.params, ["#channel", "hello"]) + + def test_lf(self): + line = irctokens.tokenise( + ":nick!user@host PRIVMSG #channel :hello\n world") + self.assertEqual(line.params, ["#channel", "hello"]) + class TokenTestNoCommand(unittest.TestCase): def test(self): def _test1():