From b95d03b74c1186a67f0a5e5ddf909b496505a3b5 Mon Sep 17 00:00:00 2001 From: Antoine Pietri Date: Wed, 11 Mar 2015 11:49:15 +0100 Subject: chat_name_hint: normalize utf8 with fallback from the channel name --- irc_im.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'irc_im.c') diff --git a/irc_im.c b/irc_im.c index d71c9ee9..2a956c44 100644 --- a/irc_im.c +++ b/irc_im.c @@ -697,7 +697,8 @@ static gboolean bee_irc_chat_name_hint(bee_t *bee, struct groupchat *c, const ch { irc_t *irc = bee->ui_data; irc_channel_t *ic = c->ui_data, *oic; - char stripped[MAX_NICK_LENGTH + 1], *full_name; + char *stripped, *full_name; + gsize bytes_written; if (ic == NULL) { return FALSE; @@ -708,18 +709,23 @@ static gboolean bee_irc_chat_name_hint(bee_t *bee, struct groupchat *c, const ch return FALSE; } - strncpy(stripped, name, MAX_NICK_LENGTH); - stripped[MAX_NICK_LENGTH] = '\0'; + stripped = g_convert_with_fallback(name, -1, "ASCII//TRANSLIT", "UTF-8", "", NULL, &bytes_written, NULL); + if (bytes_written > MAX_NICK_LENGTH) { + stripped[MAX_NICK_LENGTH] = '\0'; + } + irc_channel_name_strip(stripped); if (set_getbool(&bee->set, "lcnicks")) { nick_lc(irc, stripped); } if (stripped[0] == '\0') { + g_free(stripped); return FALSE; } full_name = g_strdup_printf("#%s", stripped); + g_free(stripped); if ((oic = irc_channel_by_name(irc, full_name))) { char *type, *chat_type; -- cgit v1.2.3