From 29ec400a8ee157510c592ac8ba1190f4abe3c5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 8 Sep 2015 09:25:05 +0200 Subject: [PATCH] irc: fix charset decoding in incoming private messages (closes #520) --- ChangeLog.asciidoc | 1 + src/plugins/irc/irc-message.c | 42 +++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index 320288892..e7891d9ad 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -31,6 +31,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] * core: fix truncated messages after a word with a length of zero on screen (for example a zero width space: U+200B) (bug #40985, issue #502) * api: fix handle of invalid escape in function string_convert_escaped_chars() +* irc: fix charset decoding in incoming private messages (issue #520) * irc: display the arrow before server name in raw buffer * irc: fix display of messages sent to server in raw buffer * irc: fix display of invalid UTF-8 chars in raw buffer diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index e0c4dcf4f..2b465abd8 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -70,7 +70,7 @@ irc_message_parse (struct t_irc_server *server, const char *message, int *pos_command, int *pos_arguments, int *pos_channel, int *pos_text) { - const char *ptr_message, *pos, *pos2, *pos3, *pos4; + const char *ptr_message, *pos, *pos2, *pos3, *pos4, *ptr_channel_found; if (tags) *tags = NULL; @@ -96,6 +96,7 @@ irc_message_parse (struct t_irc_server *server, const char *message, *pos_channel = -1; if (pos_text) *pos_text = -1; + ptr_channel_found = NULL; if (!message) return; @@ -209,6 +210,7 @@ irc_message_parse (struct t_irc_server *server, const char *message, { if (irc_channel_is_channel (server, pos)) { + ptr_channel_found = pos; pos2 = strchr (pos, ' '); if (channel) { @@ -253,6 +255,7 @@ irc_message_parse (struct t_irc_server *server, const char *message, } if (irc_channel_is_channel (server, pos2)) { + ptr_channel_found = pos2; pos4 = strchr (pos2, ' '); if (channel) { @@ -277,13 +280,38 @@ irc_message_parse (struct t_irc_server *server, const char *message, *pos_text = pos4 - message; } } - else if ((channel && !*channel) - || (pos_channel && (*pos_channel < 0))) + else { - if (channel) - *channel = weechat_strndup (pos, pos3 - pos); - if (pos_channel) - *pos_channel = pos - message; + if (ptr_channel_found) + { + if (pos[0] == ':') + pos++; + if (text) + *text = strdup (pos); + if (pos_text) + *pos_text = pos - message; + } + else + { + if (channel) + *channel = weechat_strndup (pos, pos3 - pos); + if (pos_channel) + *pos_channel = pos - message; + pos4 = strchr (pos3, ' '); + if (pos4) + { + while (pos4[0] == ' ') + { + pos4++; + } + if (pos4[0] == ':') + pos4++; + if (text) + *text = strdup (pos4); + if (pos_text) + *pos_text = pos4 - message; + } + } } } }