]> jfr.im git - irc/weechat/weechat.git/commitdiff
irc: split server command before evaluating it (issue #1643)
authorSébastien Helleu <redacted>
Sat, 22 May 2021 06:24:47 +0000 (08:24 +0200)
committerSébastien Helleu <redacted>
Sat, 22 May 2021 06:48:24 +0000 (08:48 +0200)
ChangeLog.adoc
src/plugins/irc/irc-config.c
src/plugins/irc/irc-protocol.c

index ab6ec229ecd8dca944480e5347d8bfa120b7ea85..7e1b3506e0133588da84f433f9e07beaf31fb08e 100644 (file)
@@ -52,6 +52,7 @@ Bug fixes::
   * core: prevent switching to start of visited buffers when jumping to next (issue #1591, issue #1592)
   * core: recreate buflist and fset bars on /reload when WeeChat is started without configuration files (issue #1618)
   * buflist: fix comparison of hotlists in option buflist.look.sort (issue #1621)
+  * irc: split server command before evaluating it (issue #1643)
   * xfer: make file transfer fail when option xfer.file.auto_rename is off and file already exists (issue #1633)
 
 Tests::
index ebb6c37c0fe9c9eedfb2c2c743c1a10e203d73af..0f143625a41cf1385ca8de088dfa67b4aec45b73 100644 (file)
@@ -2150,7 +2150,7 @@ irc_config_server_new_option (struct t_config_file *config_file,
                    "auto-join of channels (many commands can be separated by "
                    "\";\", use \"\\;\" for a semicolon, special variables "
                    "$nick, $channel and $server are replaced by their value) "
-                   "(note: content is evaluated, see /help eval; server "
+                   "(note: commands are evaluated, see /help eval; server "
                    "options are evaluated with ${irc_server.xxx} and "
                    "${server} is replaced by the server name)"),
                 NULL, 0, 0,
index f5f91b9e04ee0d5d85aa9982151885b92417be5b..183b83d78ed08ff46613ec2abbfcc88b38fd7b13 100644 (file)
@@ -2977,8 +2977,9 @@ IRC_PROTOCOL_CALLBACK(wallops)
 
 IRC_PROTOCOL_CALLBACK(001)
 {
-    char *server_command, **commands, **ptr_command, *command2, *slash_command;
+    char **commands, **ptr_command, *command2, *command3, *slash_command;
     char *away_msg, *usermode;
+    const char *ptr_server_command;
     int length;
 
     IRC_PROTOCOL_MIN_ARGS(3);
@@ -3035,35 +3036,41 @@ IRC_PROTOCOL_CALLBACK(001)
         free (usermode);
 
     /* execute command when connected */
-    server_command = irc_server_eval_expression (
-        server,
-        IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND));
-    if (server_command && server_command[0])
+    ptr_server_command = IRC_SERVER_OPTION_STRING(server,
+                                                  IRC_SERVER_OPTION_COMMAND);
+    if (ptr_server_command && ptr_server_command[0])
     {
         /* split command on ';' which can be escaped with '\;' */
-        commands = weechat_string_split_command (server_command, ';');
+        commands = weechat_string_split_command (ptr_server_command, ';');
         if (commands)
         {
             for (ptr_command = commands; *ptr_command; ptr_command++)
             {
-                command2 = irc_message_replace_vars (server, NULL,
-                                                     *ptr_command);
+                command2 = irc_server_eval_expression (server, *ptr_command);
                 if (command2)
                 {
-                    if (weechat_string_is_command_char (command2))
-                    {
-                        weechat_command (server->buffer, command2);
-                    }
-                    else
+                    command3 = irc_message_replace_vars (server, NULL,
+                                                         command2);
+                    if (command3)
                     {
-                        length = 1 + strlen(command2) + 1;
-                        slash_command = malloc (length);
-                        if (slash_command)
+                        if (weechat_string_is_command_char (command3))
                         {
-                            snprintf (slash_command, length, "/%s", command2);
-                            weechat_command (server->buffer, slash_command);
-                            free (slash_command);
+                            weechat_command (server->buffer, command3);
+                        }
+                        else
+                        {
+                            length = 1 + strlen(command3) + 1;
+                            slash_command = malloc (length);
+                            if (slash_command)
+                            {
+                                snprintf (slash_command, length,
+                                          "/%s", command3);
+                                weechat_command (server->buffer,
+                                                 slash_command);
+                                free (slash_command);
+                            }
                         }
+                        free (command3);
                     }
                     free (command2);
                 }
@@ -3080,8 +3087,6 @@ IRC_PROTOCOL_CALLBACK(001)
     {
         irc_server_autojoin_channels (server);
     }
-    if (server_command)
-        free (server_command);
 
     return WEECHAT_RC_OK;
 }