Skip to content

Commit 173dc7b

Browse files
committed
fix: normalize WebSocket /msgjoin channel and reject empty channels
/msgjoin was lowercasing the channel but not ensuring the leading '#'. Use _clean_channel_list so bare channel names become valid '#channel' names, and reject an empty/whitespace channel with a clear error.
1 parent 90f0491 commit 173dc7b

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎dccbot/app.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,14 @@ async def handle_ws_command(self, command: str | None, args: list[str], ws: web.
482482
raise RuntimeError("Not enough arguments")
483483
server = args.pop(0)
484484
bot = await self.bot_manager.get_bot(server)
485-
channel = args.pop(0)
485+
channels = self._clean_channel_list([args.pop(0)])
486+
if not channels:
487+
raise RuntimeError("Invalid channel")
486488
target = args.pop(0).lower().strip()
487489
await bot.queue_command({
488490
"command": "send",
489491
"user": target,
490-
"channels": [channel.lower().strip()],
492+
"channels": [channels[0]],
491493
"message": " ".join(args),
492494
})
493495
elif command == "info":

‎tests/unit/test_websocket.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,17 @@ async def test_websocket_handler_msgjoin_command(ws_session):
277277
assert call_args["channels"] == ["#channel"]
278278
assert call_args["message"] == "hello world"
279279
await ws.close()
280+
281+
282+
@pytest.mark.asyncio
283+
async def test_websocket_handler_msgjoin_normalizes_channel(ws_session):
284+
"""Test websocket /msgjoin adds # to bare channel names."""
285+
ws, mock_bot_manager = ws_session
286+
mock_bot = MagicMock()
287+
mock_bot.queue_command = AsyncMock()
288+
mock_bot_manager.get_bot = AsyncMock(return_value=mock_bot)
289+
await ws.send_str("/msgjoin server Channel target hello world")
290+
await asyncio.sleep(0.1)
291+
call_args = mock_bot.queue_command.call_args[0][0]
292+
assert call_args["channels"] == ["#channel"]
293+
await ws.close()

0 commit comments

Comments
 (0)