Mercurial > pidgin
changeset 29006:e1c01f236674
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.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 10 Feb 2010 03:32:29 +0000 |
parents | 9b0d3a48a467 |
children | a8e19b69e6b4 55515a760e87 |
files | ChangeLog ChangeLog.API libpurple/protocols/bonjour/parser.c libpurple/protocols/jabber/parser.c libpurple/xmlnode.c |
diffstat | 5 files changed, 86 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 "<br>" to a newline). + Perl: Changed: * Corrected the package names for the PurpleProxyType and
--- 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);
--- 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);
--- 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);