diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 0419caac9..15508ae39 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -91,6 +91,7 @@ Bug fixes:: * irc: add messages 415 (cannot send message to channel) and 742 (mode cannot be set) * irc: add missing tag "log3" in notify messages * irc: add missing tags "irc_cap" and "log3" in cap messages (client capability) + * irc: fix split of CTCP message with no arguments * lua: fix crash with print when the value to print is not a string (issue #1904, issue #1905) * ruby: fix crash on quit when a child process is still running (issue #1889, issue #1915) * script: remove trailing "J" (line feed char) in source of scripts displayed diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index c6fdae08b..d6fc572b0 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -1441,9 +1441,15 @@ irc_message_split_privmsg_notice (struct t_irc_message_split_context *context, pos[0] = saved_char; list_lines[i][length - 1] = '\0'; ptr_args = pos; - suffix[0] = '\01'; - suffix[1] = '\0'; } + else + { + list_lines[i][length - 1] = '\0'; + snprintf (prefix, sizeof (prefix), ":%s", list_lines[i]); + ptr_args = ""; + } + suffix[0] = '\01'; + suffix[1] = '\0'; } if (!prefix[0]) strcpy (prefix, ":"); diff --git a/tests/unit/plugins/irc/test-irc-message.cpp b/tests/unit/plugins/irc/test-irc-message.cpp index 3939060e9..605a7a19d 100644 --- a/tests/unit/plugins/irc/test-irc-message.cpp +++ b/tests/unit/plugins/irc/test-irc-message.cpp @@ -1621,24 +1621,46 @@ TEST(IrcMessage, Split) (const char *)hashtable_get (hashtable, "args2")); hashtable_free (hashtable); - /* PRIVMSG with "\x01ACTION " + 512 bytes + "\x01": 1 split */ + /* PRIVMSG with "\01ACTION\01": no split */ + hashtable = irc_message_split (server, "PRIVMSG #channel :\01ACTION\01"); + CHECK(hashtable); + LONGS_EQUAL(3, hashtable->items_count); + STRCMP_EQUAL("1", + (const char *)hashtable_get (hashtable, "count")); + STRCMP_EQUAL("PRIVMSG #channel :\01ACTION\01", + (const char *)hashtable_get (hashtable, "msg1")); + STRCMP_EQUAL("", + (const char *)hashtable_get (hashtable, "args1")); + hashtable_free (hashtable); + + /* PRIVMSG with "\01ACTION test\01": no split */ + hashtable = irc_message_split (server, "PRIVMSG #channel :\01ACTION test\01"); + CHECK(hashtable); + LONGS_EQUAL(3, hashtable->items_count); + STRCMP_EQUAL("1", + (const char *)hashtable_get (hashtable, "count")); + STRCMP_EQUAL("PRIVMSG #channel :\01ACTION test\01", + (const char *)hashtable_get (hashtable, "msg1")); + STRCMP_EQUAL("test", + (const char *)hashtable_get (hashtable, "args1")); + hashtable_free (hashtable); + + /* PRIVMSG with "\01ACTION " + 512 bytes + "\01": 1 split */ hashtable = irc_message_split (server, "PRIVMSG #channel :" - "\x01" "ACTION " - LOREM_IPSUM_512 - "\x01"); + "\01ACTION " LOREM_IPSUM_512 "\01"); CHECK(hashtable); LONGS_EQUAL(5, hashtable->items_count); STRCMP_EQUAL("2", (const char *)hashtable_get (hashtable, "count")); - STRCMP_EQUAL("PRIVMSG #channel :" "\x01" "ACTION " "Lorem ipsum dolor sit" + STRCMP_EQUAL("PRIVMSG #channel :\01ACTION Lorem ipsum dolor sit" " amet, consectetur adipiscing elit. Fusce auctor ac leo ut " "maximus. Curabitur vestibulum facilisis neque, vitae sodale" "s elit pulvinar ac. Mauris suscipit pharetra metus eu hendr" "erit. Proin viverra ligula ut nibh malesuada, vel vehicula " "leo pulvinar. Nullam tellus dolor, posuere sed orci in, pre" "tium fermentum ante. Donec a quam vulputate, fermentum nisi" - " nec, convallis" "\x01", + " nec, convallis\01", (const char *)hashtable_get (hashtable, "msg1")); STRCMP_EQUAL("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fu" "sce auctor ac leo ut maximus. Curabitur vestibulum facilisi" @@ -1648,9 +1670,9 @@ TEST(IrcMessage, Split) "uere sed orci in, pretium fermentum ante. Donec a quam vulp" "utate, fermentum nisi nec, convallis", (const char *)hashtable_get (hashtable, "args1")); - STRCMP_EQUAL("PRIVMSG #channel :" "\x01" "ACTION " "sapien. Vestibulum ma" + STRCMP_EQUAL("PRIVMSG #channel :\01ACTION sapien. Vestibulum ma" "lesuada dui eget iaculis sagittis. Praesent egestas non ex " - "quis blandit. Maecenas quis leo nunc. In." "\x01", + "quis blandit. Maecenas quis leo nunc. In.\01", (const char *)hashtable_get (hashtable, "msg2")); STRCMP_EQUAL("sapien. Vestibulum malesuada dui eget iaculis sagittis. Pra" "esent egestas non ex quis blandit. Maecenas quis leo nunc. "