mirror of https://github.com/jesopo/irctokens
truncate on \r and \n too
This commit is contained in:
parent
93f1079ae7
commit
14d38192cf
|
@ -109,7 +109,10 @@ def tokenise(
|
||||||
else:
|
else:
|
||||||
dline = line
|
dline = line
|
||||||
|
|
||||||
if "\x00" in dline:
|
for badchar in set(dline) & {"\x00", "\r", "\n"}:
|
||||||
dline, _ = dline.split("\x00", 1)
|
badindex = dline.find(badchar)
|
||||||
|
if not badindex == -1:
|
||||||
|
# truncate before this bad character
|
||||||
|
dline = dline[:badindex]
|
||||||
|
|
||||||
return _tokenise(dline)
|
return _tokenise(dline)
|
||||||
|
|
|
@ -71,12 +71,22 @@ class TokenTestAll(unittest.TestCase):
|
||||||
self.assertEqual(line.command, "PRIVMSG")
|
self.assertEqual(line.command, "PRIVMSG")
|
||||||
self.assertEqual(line.params, ["#channel", "hello world"])
|
self.assertEqual(line.params, ["#channel", "hello world"])
|
||||||
|
|
||||||
class TokenTestNul(unittest.TestCase):
|
class TokenTestTruncate(unittest.TestCase):
|
||||||
def test(self):
|
def test_null(self):
|
||||||
line = irctokens.tokenise(
|
line = irctokens.tokenise(
|
||||||
":nick!user@host PRIVMSG #channel :hello\x00 world")
|
":nick!user@host PRIVMSG #channel :hello\x00 world")
|
||||||
self.assertEqual(line.params, ["#channel", "hello"])
|
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):
|
class TokenTestNoCommand(unittest.TestCase):
|
||||||
def test(self):
|
def test(self):
|
||||||
def _test1():
|
def _test1():
|
||||||
|
|
Loading…
Reference in New Issue