# HG changeset patch # User John Bailey # Date 1191707934 0 # Node ID c6232f341ea54cb90f04247c7717d6ca81f90750 # Parent 97bda4a072d2b73fd50fbb79d886979bdf262c6b Fix the mIRC format handling bug that causes incorrect display of received text. The behavior of g_markup_escape_text changed in glib 2.12, which caused this bug. This fix copies the working version of said function and the private helper function append_escaped_text() into our IRC prpl. Fixes #3467 diff -r 97bda4a072d2 -r c6232f341ea5 libpurple/protocols/irc/irc.h --- a/libpurple/protocols/irc/irc.h Sat Oct 06 17:49:40 2007 +0000 +++ b/libpurple/protocols/irc/irc.h Sat Oct 06 21:58:54 2007 +0000 @@ -99,6 +99,8 @@ int irc_send(struct irc_conn *irc, const char *buf); gboolean irc_blist_timeout(struct irc_conn *irc); +char *irc_escape_privmsg(const char *text, gssize length); + char *irc_mirc2html(const char *string); char *irc_mirc2txt(const char *string); diff -r 97bda4a072d2 -r c6232f341ea5 libpurple/protocols/irc/msgs.c --- a/libpurple/protocols/irc/msgs.c Sat Oct 06 17:49:40 2007 +0000 +++ b/libpurple/protocols/irc/msgs.c Sat Oct 06 21:58:54 2007 +0000 @@ -1066,7 +1066,7 @@ return; } - msg = g_markup_escape_text(tmp, -1); + msg = irc_escape_privmsg(tmp, -1); g_free(tmp); tmp = irc_mirc2html(msg); diff -r 97bda4a072d2 -r c6232f341ea5 libpurple/protocols/irc/parse.c --- a/libpurple/protocols/irc/parse.c Sat Oct 06 17:49:40 2007 +0000 +++ b/libpurple/protocols/irc/parse.c Sat Oct 06 21:58:54 2007 +0000 @@ -281,6 +281,61 @@ return purple_utf8_salvage(string); } +/* This function is shamelessly stolen from glib--it is an old version of the + * private function append_escaped_text, used by g_markup_escape_text, whose + * behavior changed in glib 2.12. */ +static void irc_append_escaped_text(GString *str, const char *text, gssize length) +{ + const char *p = text; + const char *end = text + length; + const char *next = NULL; + + while(p != end) { + next = g_utf8_next_char(p); + + switch(*p) { + case '&': + g_string_append(str, "&"); + break; + case '<': + g_string_append(str, "<"); + break; + case '>': + g_string_append(str, ">"); + break; + case '\'': + g_string_append(str, "'"); + break; + case '"': + g_string_append(str, """); + break; + default: + g_string_append_len(str, p, next - p); + break; + } + + p = next; + } +} + +/* This function is shamelessly stolen from glib--it is an old version of the + * function g_markup_escape_text, whose behavior changed in glib 2.12. */ +char *irc_escape_privmsg(const char *text, gssize length) +{ + GString *str; + + g_return_val_if_fail(text != NULL, NULL); + + if(length < 0) + length = strlen(text); + + str = g_string_sized_new(length); + + irc_append_escaped_text(str, text, length); + + return g_string_free(str, FALSE); +} + /* XXX tag closings are not necessarily correctly nested here! If we * get a ^O or reach the end of the string and there are open * tags, they are closed in a fixed order ... this means, for