From df9c32b0c3ef78c9a8866779e554994f694139f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 16 Oct 2021 09:42:25 +0200 Subject: [PATCH] irc: use parsed command parameters in "322" command callback --- src/plugins/irc/irc-protocol.c | 22 ++++++++++---------- tests/unit/plugins/irc/test-irc-protocol.cpp | 8 +++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 5510cccaa..b7727ebf4 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -4224,21 +4224,19 @@ IRC_PROTOCOL_CALLBACK(321) * Callback for the IRC command "322": channel for /list. * * Command looks like: - * :server 322 mynick #channel 3 :topic of channel + * 322 mynick #channel 3 :topic of channel */ IRC_PROTOCOL_CALLBACK(322) { - char *pos_topic; + char *str_params; - IRC_PROTOCOL_MIN_ARGS(5); - - pos_topic = (argc > 5) ? - ((argv_eol[5][0] == ':') ? argv_eol[5] + 1 : argv_eol[5]) : NULL; + IRC_PROTOCOL_MIN_PARAMS(3); if (!server->cmd_list_regexp || - (regexec (server->cmd_list_regexp, argv[3], 0, NULL, 0) == 0)) + (regexec (server->cmd_list_regexp, params[1], 0, NULL, 0) == 0)) { + str_params = irc_protocol_string_params (params, 3, num_params - 1); weechat_printf_date_tags ( irc_msgbuffer_get_target_buffer ( server, NULL, command, "list", NULL), @@ -4247,14 +4245,16 @@ IRC_PROTOCOL_CALLBACK(322) "%s%s%s%s(%s%s%s)%s%s%s", weechat_prefix ("network"), IRC_COLOR_CHAT_CHANNEL, - argv[3], + params[1], IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_RESET, - argv[4], + params[2], IRC_COLOR_CHAT_DELIMITERS, IRC_COLOR_RESET, - (pos_topic && pos_topic[0]) ? ": " : "", - (pos_topic && pos_topic[0]) ? pos_topic : ""); + (str_params && str_params[0]) ? ": " : "", + (str_params && str_params[0]) ? str_params : ""); + if (str_params) + free (str_params); } return WEECHAT_RC_OK; diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp index 40a39857c..58d316de1 100644 --- a/tests/unit/plugins/irc/test-irc-protocol.cpp +++ b/tests/unit/plugins/irc/test-irc-protocol.cpp @@ -2589,13 +2589,13 @@ TEST(IrcProtocolWithServer, 322) { SRV_INIT; - /* not enough arguments */ + /* not enough parameters */ RECV(":server 322"); - CHECK_ERROR_ARGS("322", 2, 5); + CHECK_ERROR_PARAMS("322", 0, 3); RECV(":server 322 alice"); - CHECK_ERROR_ARGS("322", 3, 5); + CHECK_ERROR_PARAMS("322", 1, 3); RECV(":server 322 alice #test"); - CHECK_ERROR_ARGS("322", 4, 5); + CHECK_ERROR_PARAMS("322", 2, 3); RECV(":server 322 alice #test 3"); CHECK_SRV("-- #test(3)");