diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-message.c | 15 | ||||
-rw-r--r-- | tests/unit/plugins/irc/test-irc-message.cpp | 16 |
3 files changed, 26 insertions, 6 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 1705fca1f..b4ed649df 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -57,6 +57,7 @@ Bug fixes:: * core: fix crash when a custom bar item name is already used by a default bar item (issue #2034) * core: fix random timeouts when a lot of concurrent processes are launched with hook_process (issue #2033) * api: return NULL instead of empty infolist "key" when context is not found + * irc: fix display of self messages when the message split fails due to inconsistent max lengths sent by the server in message 005 * irc: display messages 730/731 (monitored nicks online/offline) even if command `/notify` was not used (issue #2049) * irc: remove trailing "\r\n" in signals "irc_out" and "irc_outtags" when messages are queued * irc: fix target buffer of IRC message 337 (whois reply: "is hiding their idle time") diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index 261a9359a..0b27d66e9 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -1055,9 +1055,6 @@ irc_message_split_string (struct t_irc_message_split_context *context, if (suffix) max_length -= strlen (suffix); - if (max_length < 2) - return 0; - /* debug message */ if (weechat_irc_plugin->debug >= 2) { @@ -1069,17 +1066,23 @@ irc_message_split_string (struct t_irc_message_split_context *context, max_length); } - if (!arguments || !arguments[0]) + if ((max_length < 2) || !arguments || !arguments[0]) { - snprintf (message, sizeof (message), "%s%s%s %s%s%s%s", + /* + * max length is not known (server probably sent values that are not + * consistent), or no arguments => in this case, we just return message + * as-is (no split) + */ + snprintf (message, sizeof (message), "%s%s%s %s%s%s%s%s", (host) ? host : "", (host) ? " " : "", command, (target) ? target : "", (target && target[0]) ? " " : "", (prefix) ? prefix : "", + (arguments) ? arguments : "", (suffix) ? suffix : ""); - irc_message_split_add (context, tags, message, ""); + irc_message_split_add (context, tags, message, (arguments) ? arguments : ""); (context->number)++; return 1; } diff --git a/tests/unit/plugins/irc/test-irc-message.cpp b/tests/unit/plugins/irc/test-irc-message.cpp index e3e6b4c9f..aed8d4fe8 100644 --- a/tests/unit/plugins/irc/test-irc-message.cpp +++ b/tests/unit/plugins/irc/test-irc-message.cpp @@ -1137,6 +1137,7 @@ TEST(IrcMessage, Split) struct t_hashtable *hashtable; const char *ptr_msg, *pos1, *pos2; char batch_ref[512], msg[4096]; + int old_nick_max_length; server = irc_server_alloc ("test_split_msg"); CHECK(server); @@ -1552,6 +1553,21 @@ TEST(IrcMessage, Split) (const char *)hashtable_get (hashtable, "args1")); hashtable_free (hashtable); + /* PRIVMSG with small content but inconsistent max length: no split */ + old_nick_max_length = server->nick_max_length; + server->nick_max_length = 4096; + hashtable = irc_message_split (server, "PRIVMSG #channel :test"); + CHECK(hashtable); + LONGS_EQUAL(3, hashtable->items_count); + STRCMP_EQUAL("1", + (const char *)hashtable_get (hashtable, "count")); + STRCMP_EQUAL("PRIVMSG #channel :test", + (const char *)hashtable_get (hashtable, "msg1")); + STRCMP_EQUAL("test", + (const char *)hashtable_get (hashtable, "args1")); + hashtable_free (hashtable); + server->nick_max_length = old_nick_max_length; + /* PRIVMSG with 512 bytes of content: 1 split */ hashtable = irc_message_split (server, "PRIVMSG #channel :" LOREM_IPSUM_512); |