Skip to content

Commit

Permalink
ircdb.checkIgnored: return False for messages from servers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jlu5 authored and progval committed Feb 6, 2024
1 parent a2e55ca commit 3e5291f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ircdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,12 @@ def checkIgnored(self, hostmask):
return True
if world.testing:
return False
assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
if not ircutils.isUserHostmask(hostmask):
# Treat messages from a server (e.g. snomasks) as not ignored, as
# the ignores system doesn't understand them
if '.' not in hostmask:
raise ValueError("Expected full prefix, got %r" % hostmask)
return False
if self.checkBan(hostmask):
return True
if self.ignores.match(hostmask):
Expand Down
17 changes: 17 additions & 0 deletions test/test_ircdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,23 @@ def testIgnored(self):
c.removeBan(banmask)
self.assertFalse(c.checkIgnored(prefix))

# Only full n!u@h is accepted here
self.assertRaises(ValueError, c.checkIgnored, 'foo')

def testIgnoredServerNames(self):
c = ircdb.IrcChannel()
# Server names are not handled by the ignores system, so this is false
self.assertFalse(c.checkIgnored('irc.example.com'))
# But we should treat full prefixes that match nick!user@host normally,
# even if they include "." like a server name
prefix = 'irc.example.com!bar@baz'
banmask = ircutils.banmask(prefix)
self.assertFalse(c.checkIgnored(prefix))
c.addIgnore(banmask)
self.assertTrue(c.checkIgnored(prefix))
c.removeIgnore(banmask)
self.assertFalse(c.checkIgnored(prefix))

class IrcNetworkTestCase(IrcdbTestCase):
def testDefaults(self):
n = ircdb.IrcNetwork()
Expand Down

0 comments on commit 3e5291f

Please sign in to comment.