Skip to content

Commit 3e5291f

Browse files
jlu5progval
authored andcommitted
ircdb.checkIgnored: return False for messages from servers
These do not pass the `ircutils.isUserHostmask` check despite being a valid msg.prefix. We should probably return gracefully here instead of forcing plugins to deal with such a case themselves. Closes GH-1548
1 parent a2e55ca commit 3e5291f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/ircdb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,12 @@ def checkIgnored(self, hostmask):
468468
return True
469469
if world.testing:
470470
return False
471-
assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
471+
if not ircutils.isUserHostmask(hostmask):
472+
# Treat messages from a server (e.g. snomasks) as not ignored, as
473+
# the ignores system doesn't understand them
474+
if '.' not in hostmask:
475+
raise ValueError("Expected full prefix, got %r" % hostmask)
476+
return False
472477
if self.checkBan(hostmask):
473478
return True
474479
if self.ignores.match(hostmask):

test/test_ircdb.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,23 @@ def testIgnored(self):
350350
c.removeBan(banmask)
351351
self.assertFalse(c.checkIgnored(prefix))
352352

353+
# Only full n!u@h is accepted here
354+
self.assertRaises(ValueError, c.checkIgnored, 'foo')
355+
356+
def testIgnoredServerNames(self):
357+
c = ircdb.IrcChannel()
358+
# Server names are not handled by the ignores system, so this is false
359+
self.assertFalse(c.checkIgnored('irc.example.com'))
360+
# But we should treat full prefixes that match nick!user@host normally,
361+
# even if they include "." like a server name
362+
prefix = 'irc.example.com!bar@baz'
363+
banmask = ircutils.banmask(prefix)
364+
self.assertFalse(c.checkIgnored(prefix))
365+
c.addIgnore(banmask)
366+
self.assertTrue(c.checkIgnored(prefix))
367+
c.removeIgnore(banmask)
368+
self.assertFalse(c.checkIgnored(prefix))
369+
353370
class IrcNetworkTestCase(IrcdbTestCase):
354371
def testDefaults(self):
355372
n = ircdb.IrcNetwork()

0 commit comments

Comments
 (0)