mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 12:49:24 +01:00
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:
parent
5baf87ddba
commit
e19282a2d3
@ -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
|
||||
|
@ -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('#'))
|
||||
|
Loading…
Reference in New Issue
Block a user