3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 04:59:24 +01:00

ircs2s_common: don't strip away other whitespace chars when tokenizing

This commit is contained in:
James Lu 2021-07-14 20:09:19 -07:00
parent 3f59dcd884
commit bc3a7abe02
3 changed files with 14 additions and 3 deletions

View File

@ -97,7 +97,7 @@ class IRCCommonProtocol(IRCNetwork):
joined_arg = ' '.join(args[idx:])[1:] # Cut off the leading : as well
real_args.append(joined_arg)
break
elif arg.strip(): # Skip empty args that aren't part of the multi-word arg
elif arg.strip(' '): # Skip empty args that aren't part of the multi-word arg
real_args.append(arg)
return real_args

View File

@ -29,7 +29,7 @@ class DummySocket():
return None
'''
def recv(bufsize, *args):
def recv(self, bufsize, *args):
raise NotImplementedError
def send(self, data):
@ -343,7 +343,7 @@ class BaseProtocolTest(unittest.TestCase):
[('+v', '100'), ('+i', None), ('+p', None)]
)
def test_parse_modes_channel_rfc(self):
def test_parse_modes_channel_rfc2(self):
# These are basic tests that only use RFC 1459 defined modes.
# IRCds supporting more complex modes can define new test cases if needed.
c = self.p.channels['#testruns'] = Channel(self.p, name='#testruns')

View File

@ -111,5 +111,16 @@ class MessageParserTest(unittest.TestCase):
# N.B. skipping msg-join tests because PyLink doesn't think about messages that way
### Custom test cases
def testMessageSplitSpaces(self):
# Test that tokenization ignores empty fields, but doesn't strip away other types of whitespace
f = IRCCommonProtocol.parse_prefixed_args
self.assertEqual(f(":foo PRIVMSG #test :message"), ["foo", "PRIVMSG", "#test", "message"])
self.assertEqual(f(":123LOLWUT NICK cursed\u3000nickname"), ["123LOLWUT", "NICK", "cursed\u3000nickname"])
self.assertEqual(f(":123LOLWUT MODE ## +ov \x1f checking"),
["123LOLWUT", "MODE", "##", "+ov", "\x1f", "checking"])
self.assertEqual(f(":123LOLWUT MODE ## +ov \u3000 checking"),
["123LOLWUT", "MODE", "##", "+ov", "\u3000", "checking"])
if __name__ == '__main__':
unittest.main()