# HG changeset patch # User Paul Aurich # Date 1265772749 0 # Node ID e1c01f236674b870f3e3c8b8e1396bf426c91ef7 # Parent 9b0d3a48a4675efff8e2589631806d8edb968a19 Correctly parse "<br>" in an XML attribute. Closes #11318. If nobody has objections, I intend to add purple_unescape_text() to util.[ch] for 2.7.0. diff -r 9b0d3a48a467 -r e1c01f236674 ChangeLog --- a/ChangeLog Tue Feb 09 06:56:00 2010 +0000 +++ b/ChangeLog Wed Feb 10 03:32:29 2010 +0000 @@ -10,6 +10,8 @@ * When looking up DNS records, use the type of record returned by the server (instead of the type we asked for) to determine how to process the record. + * Fix an issue with parsing XML attributes that contain "<br>". + See ChangeLog.API for more details. General: * Correctly disable all missing dependencies when using the diff -r 9b0d3a48a467 -r e1c01f236674 ChangeLog.API --- a/ChangeLog.API Tue Feb 09 06:56:00 2010 +0000 +++ b/ChangeLog.API Wed Feb 10 03:32:29 2010 +0000 @@ -7,6 +7,12 @@ purple_xfer_request_denied if an error is found when selecting a file to send. Request denied is still used when a receive request is not allowed. + * xmlnode_from_str now properly handles paring an attribute which + contain "<br>", which were previously transformed into a + newline character (libxml2 unescapes all entities except + representations of '&', and libpurple's purple_unescape_html + converts "
" to a newline). + Perl: Changed: * Corrected the package names for the PurpleProxyType and diff -r 9b0d3a48a467 -r e1c01f236674 libpurple/protocols/bonjour/parser.c --- a/libpurple/protocols/bonjour/parser.c Tue Feb 09 06:56:00 2010 +0000 +++ b/libpurple/protocols/bonjour/parser.c Wed Feb 10 03:32:29 2010 +0000 @@ -49,6 +49,31 @@ return FALSE; } +static char *purple_unescape_text(const char *in) +{ + GString *ret; + const char *c = in; + + if (in == NULL) + return NULL; + + ret = g_string_new(""); + while (*c) { + int len; + const char *ent; + + if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) { + g_string_append(ret, ent); + c += len; + } else { + g_string_append_c(ret, *c); + c++; + } + } + + return g_string_free(ret, FALSE); +} + static void bonjour_parser_element_start_libxml(void *user_data, const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace, @@ -102,7 +127,7 @@ attrib[attrib_len] = '\0'; txt = attrib; - attrib = purple_unescape_html(txt); + attrib = purple_unescape_text(txt); g_free(txt); xmlnode_set_attrib_full(node, name, attrib_ns, prefix, attrib); g_free(attrib); diff -r 9b0d3a48a467 -r e1c01f236674 libpurple/protocols/jabber/parser.c --- a/libpurple/protocols/jabber/parser.c Tue Feb 09 06:56:00 2010 +0000 +++ b/libpurple/protocols/jabber/parser.c Wed Feb 10 03:32:29 2010 +0000 @@ -31,6 +31,31 @@ #include "util.h" #include "xmlnode.h" +static char *purple_unescape_text(const char *in) +{ + GString *ret; + const char *c = in; + + if (in == NULL) + return NULL; + + ret = g_string_new(""); + while (*c) { + int len; + const char *ent; + + if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) { + g_string_append(ret, ent); + c += len; + } else { + g_string_append_c(ret, *c); + c++; + } + } + + return g_string_free(ret, FALSE); +} + static void jabber_parser_element_start_libxml(void *user_data, const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace, @@ -89,7 +114,7 @@ char *attrib = g_strndup((gchar *)attributes[i+3], attrib_len); txt = attrib; - attrib = purple_unescape_html(txt); + attrib = purple_unescape_text(txt); g_free(txt); xmlnode_set_attrib_full(node, name, attrib_ns, prefix, attrib); g_free(attrib); diff -r 9b0d3a48a467 -r e1c01f236674 libpurple/xmlnode.c --- a/libpurple/xmlnode.c Tue Feb 09 06:56:00 2010 +0000 +++ b/libpurple/xmlnode.c Wed Feb 10 03:32:29 2010 +0000 @@ -545,6 +545,31 @@ return xml_with_declaration; } +static char *purple_unescape_text(const char *in) +{ + GString *ret; + const char *c = in; + + if (in == NULL) + return NULL; + + ret = g_string_new(""); + while (*c) { + int len; + const char *ent; + + if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) { + g_string_append(ret, ent); + c += len; + } else { + g_string_append_c(ret, *c); + c++; + } + } + + return g_string_free(ret, FALSE); +} + struct _xmlnode_parser_data { xmlnode *current; gboolean error; @@ -590,7 +615,7 @@ int attrib_len = attributes[i+4] - attributes[i+3]; char *attrib = g_strndup((const char *)attributes[i+3], attrib_len); txt = attrib; - attrib = purple_unescape_html(txt); + attrib = purple_unescape_text(txt); g_free(txt); xmlnode_set_attrib_full(node, name, NULL, prefix, attrib); g_free(attrib);