Actually parse weird hostmasks like RFC1459 recommends

Thanks to @Noisytoot for pointing out the RFC actually specific them
with this:

<user>       ::= <nonwhite> { <nonwhite> }
This commit is contained in:
Valentin Lorentz 2021-07-14 23:42:35 +02:00
parent 5baf87ddba
commit e19282a2d3
2 changed files with 11 additions and 4 deletions

View File

@ -64,7 +64,7 @@ def warning(s, *args):
"""Prints a debug string. Most likely replaced by our logging debug."""
print('###', s % args)
userHostmaskRe = re.compile(r'^(?P<nick>\S+?)!(?P<user>\S+?)@(?P<host>\S+)$')
userHostmaskRe = re.compile(r'^(?P<nick>\S+?)!(?P<user>\S+)@(?P<host>\S+?)$')
def isUserHostmask(s):
"""Returns whether or not the string s is a valid User hostmask."""
return userHostmaskRe.match(s) is not None

View File

@ -118,11 +118,18 @@ class FunctionsTestCase(SupyTestCase):
self.assertEqual(ircutils.splitHostmask('foo!bar@baz'),
('foo', 'bar', 'baz'))
# Extravagant cases that never happen on real networks:
# This ones are technically allowed by RFC1459, but never happens in
# practice:
self.assertEqual(ircutils.splitHostmask('foo!bar!qux@quux'),
('foo', 'bar!qux', 'quux'))
self.assertEqual(ircutils.splitHostmask('foo!bar@baz@quux'),
('foo', 'bar@baz', 'quux'))
self.assertEqual(ircutils.splitHostmask('foo!bar@baz!qux@quux'),
('foo', 'bar@baz!qux', 'quux'))
# And this one in garbage, let's just make sure we don't crash:
self.assertEqual(ircutils.splitHostmask('foo!bar@baz!qux'),
('foo', 'bar', 'baz!qux'))
self.assertEqual(ircutils.splitHostmask('foo!bar@baz!qux@quux'),
('foo', 'bar', 'baz!qux@quux'))
def testIsChannel(self):
self.assertTrue(ircutils.isChannel('#'))