1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 22:06:38 +02:00

irc: fix format of IRC tags displayed in messages (closes #1929)

Changes:

- use "=" to separate key from value, add it only if value is set (any string,
  including empty string)
- do not convert "_" to "-" in key
This commit is contained in:
Sébastien Helleu
2023-05-14 21:25:20 +02:00
parent 46b9428f9e
commit bd4507e99d
3 changed files with 40 additions and 29 deletions
+1
View File
@@ -68,6 +68,7 @@ Bug fixes::
* api: readjust string size in function string_dyn_free when string is not freed
* buflist: do not display keys added in default context on first load
* fset: remove scroll to top of fset buffer when options are added or removed (issue #1892)
* irc: fix format of IRC tags displayed in messages (use "=" to separate key from value, do not convert "_" to "-") (issue #1929)
* irc: reset all internal servers variables when disconnecting
* irc: fix join of channels in "autojoin" server option on first connection to server if auto reconnection is performed (issue #1873)
* irc: update autojoin option with redirected channels when autojoin_dynamic is enabled (issue #1898)
+12 -9
View File
@@ -124,11 +124,15 @@ irc_protocol_tags_add_cb (void *data,
const void *key,
const void *value)
{
char **str_tags, *str_temp, *str_temp2;
const char *ptr_key, *ptr_value;
char **str_tags, *str_temp;
/* make C compiler happy */
(void) hashtable;
ptr_key = (const char *)key;
ptr_value = (const char *)value;
str_tags = (char **)data;
if (*str_tags[0])
@@ -137,18 +141,17 @@ irc_protocol_tags_add_cb (void *data,
weechat_string_dyn_concat (str_tags, "irc_tag_", -1);
/* key */
str_temp = weechat_string_replace ((const char *)key, ",", ";");
str_temp2 = weechat_string_replace (str_temp, "_", "-");
if (str_temp2)
weechat_string_dyn_concat (str_tags, str_temp2, -1);
str_temp = weechat_string_replace (ptr_key, ",", ";");
weechat_string_dyn_concat (str_tags, str_temp, -1);
if (str_temp)
free (str_temp);
if (str_temp2)
free (str_temp2);
weechat_string_dyn_concat (str_tags, "_", -1);
/* separator between key and value */
if (ptr_value)
weechat_string_dyn_concat (str_tags, "=", -1);
/* value */
str_temp = weechat_string_replace ((const char *)value, ",", ";");
str_temp = weechat_string_replace (ptr_value, ",", ";");
weechat_string_dyn_concat (str_tags, str_temp, -1);
if (str_temp)
free (str_temp);
+27 -20
View File
@@ -261,6 +261,8 @@ TEST(IrcProtocol, Tags)
NULL, NULL);
hashtable_set (tags_2, "key1", "value1");
hashtable_set (tags_2, "key_2,comma", "value2,comma");
hashtable_set (tags_2, "key_3_empty", "");
hashtable_set (tags_2, "key_4_null", NULL);
POINTERS_EQUAL(NULL, irc_protocol_tags (NULL, NULL, NULL, NULL, NULL, NULL));
@@ -275,13 +277,16 @@ TEST(IrcProtocol, Tags)
irc_protocol_tags (NULL, "privmsg", tags_empty, NULL, NULL, NULL));
STRCMP_EQUAL("irc_join,log4",
irc_protocol_tags (NULL, "join", tags_empty, NULL, NULL, NULL));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,log1",
STRCMP_EQUAL("irc_privmsg,irc_tag_key1=value1,log1",
irc_protocol_tags (NULL, "privmsg", tags_1, NULL, NULL, NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,log4",
STRCMP_EQUAL("irc_join,irc_tag_key1=value1,log4",
irc_protocol_tags (NULL, "join", tags_1, NULL, NULL, NULL));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,log1",
STRCMP_EQUAL("irc_privmsg,irc_tag_key1=value1,"
"irc_tag_key_2;comma=value2;comma,irc_tag_key_3_empty=,"
"irc_tag_key_4_null,log1",
irc_protocol_tags (NULL, "privmsg", tags_2, NULL, NULL, NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,log4",
STRCMP_EQUAL("irc_join,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,log4",
irc_protocol_tags (NULL, "join", tags_2, NULL, NULL, NULL));
/* command + extra_tags */
@@ -295,32 +300,34 @@ TEST(IrcProtocol, Tags)
irc_protocol_tags (NULL, "join", NULL, "tag1,tag2", NULL, NULL));
/* command + irc_msg_tags + extra_tags + nick */
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,log1",
STRCMP_EQUAL("irc_privmsg,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,log1",
irc_protocol_tags (NULL, "privmsg", tags_2, "tag1,tag2", "", NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,log4",
STRCMP_EQUAL("irc_join,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,log4",
irc_protocol_tags (NULL, "join", tags_2, "tag1,tag2", "", NULL));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_alice,log1",
STRCMP_EQUAL("irc_privmsg,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,nick_alice,log1",
irc_protocol_tags (NULL, "privmsg", tags_2, "tag1,tag2", "alice", NULL));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_bob,log4",
STRCMP_EQUAL("irc_join,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,nick_bob,log4",
irc_protocol_tags (NULL, "join", tags_2, "tag1,tag2", "bob", NULL));
/* command + irc_msg_tags + extra_tags + nick + address */
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_alice,log1",
STRCMP_EQUAL("irc_privmsg,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,nick_alice,log1",
irc_protocol_tags (NULL, "privmsg", tags_2, "tag1,tag2", "alice", ""));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_bob,log4",
STRCMP_EQUAL("irc_join,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,nick_bob,log4",
irc_protocol_tags (NULL, "join", tags_2, "tag1,tag2", "bob", ""));
STRCMP_EQUAL("irc_privmsg,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_alice,host_example.com,log1",
STRCMP_EQUAL("irc_privmsg,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,nick_alice,"
"host_example.com,log1",
irc_protocol_tags (NULL, "privmsg", tags_2, "tag1,tag2", "alice",
"example.com"));
STRCMP_EQUAL("irc_join,irc_tag_key1_value1,irc_tag_key-2;comma_value2;comma,"
"tag1,tag2,nick_bob,host_example.com,log4",
STRCMP_EQUAL("irc_join,irc_tag_key1=value1,irc_tag_key_2;comma=value2;comma,"
"irc_tag_key_3_empty=,irc_tag_key_4_null,tag1,tag2,nick_bob,"
"host_example.com,log4",
irc_protocol_tags (NULL, "join", tags_2, "tag1,tag2", "bob",
"example.com"));