truncate on \r and \n too

This commit is contained in:
jesopo 2022-01-28 17:27:48 +00:00
parent 93f1079ae7
commit 14d38192cf
2 changed files with 17 additions and 4 deletions

View File

@ -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)

View File

@ -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():