ircutils: split ! and @ in hostmasks from the right

This fixes /names parsing when ! is a prefix character and userhost-in-names is enabled: previously, strings such as "!@user!ident@some.host" were incorrectly split into "" for nick and "@user!ident@some.host" for ident@host.
This commit is contained in:
James Lu 2017-12-17 04:18:36 -05:00
parent dbbd7b4c4e
commit 37a42b0e3b
2 changed files with 9 additions and 2 deletions

View File

@ -90,8 +90,8 @@ def splitHostmask(hostmask):
"""hostmask => (nick, user, host) """hostmask => (nick, user, host)
Returns the nick, user, host of a user hostmask.""" Returns the nick, user, host of a user hostmask."""
assert isUserHostmask(hostmask) assert isUserHostmask(hostmask)
nick, rest = hostmask.split('!', 1) nick, rest = hostmask.rsplit('!', 1)
user, host = rest.split('@', 1) user, host = rest.rsplit('@', 1)
return (minisix.intern(nick), minisix.intern(user), minisix.intern(host)) return (minisix.intern(nick), minisix.intern(user), minisix.intern(host))
def joinHostmask(nick, ident, host): def joinHostmask(nick, ident, host):

View File

@ -266,6 +266,13 @@ class FunctionsTestCase(SupyTestCase):
def testNickFromHostmask(self): def testNickFromHostmask(self):
self.assertEqual(ircutils.nickFromHostmask('nick!user@host.domain.tld'), self.assertEqual(ircutils.nickFromHostmask('nick!user@host.domain.tld'),
'nick') 'nick')
# Hostmasks with user prefixes are sent via userhost-in-names. We need to
# properly handle the case where ! is a prefix and not grab '' as the nick
# instead.
self.assertEqual(ircutils.nickFromHostmask('@nick!user@some.other.host'),
'@nick')
self.assertEqual(ircutils.nickFromHostmask('!@nick!user@some.other.host'),
'!@nick')
def testToLower(self): def testToLower(self):
self.assertEqual('jemfinch', ircutils.toLower('jemfinch')) self.assertEqual('jemfinch', ircutils.toLower('jemfinch'))