Skip to content

Commit

Permalink
Merge pull request #2312 from sopel-irc/graceful-userhost-in-names
Browse files Browse the repository at this point in the history
coretasks: gracefully handle missing hostmask with userhost-in-names
  • Loading branch information
dgw committed Jun 28, 2022
2 parents 89d631d + 6c25edc commit 4d80d3d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 13 additions & 4 deletions sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,20 @@ def handle_names(bot, trigger):

names = trigger.split()
for name in names:
username = hostname = None

if uhnames or userhost_in_names:
name, mask = name.rsplit('!', 1)
username, hostname = mask.split('@', 1)
else:
username = hostname = None
try:
name, mask = name.rsplit('!', 1)
username, hostname = mask.split('@', 1)
except ValueError:
# server advertised either UHNAMES or userhost-in-names, but
# isn't sending the hostmask with all listed nicks
# It's probably ZNC. https://github.com/znc/znc/issues/1224
LOGGER.debug(
'%s is enabled, but still got RPL_NAMREPLY item without a hostmask. '
'IRC server/bouncer is not spec compliant.',
'UHNAMES' if uhnames else 'userhost-in-names')

priv = 0
for prefix, value in mapping.items():
Expand Down
16 changes: 16 additions & 0 deletions test/test_coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

from datetime import datetime, timezone
import logging

import pytest

Expand Down Expand Up @@ -558,3 +559,18 @@ def test_join_time(mockbot):
assert mockbot.channels["#test"].join_time == datetime(
2021, 1, 1, 12, 0, 0, 15000, tzinfo=timezone.utc
)


def test_handle_rpl_namreply_with_malformed_uhnames(mockbot, caplog):
"""Make sure Sopel can cope with expected but missing hostmask in 353"""
caplog.set_level(logging.DEBUG)
mockbot.on_message(
':somenet.behind.znc 005 Sopel '
'UHNAMES '
':are supported by this server')
mockbot.on_message(
':somenet.behind.znc 353 Sopel = #sopel '
':[email protected] incorrect')

assert len(caplog.messages) == 1
assert 'RPL_NAMREPLY item without a hostmask' in caplog.messages[0]

0 comments on commit 4d80d3d

Please sign in to comment.