pidgin: 0085c32a: Correctly parse "<br>" in an XML a.

darkrain42 at pidgin.im darkrain42 at pidgin.im
Tue Feb 9 23:11:36 EST 2010


-----------------------------------------------------------------
Revision: 0085c32abf29d034d30feef1ffb1d483e316a9a8
Ancestor: 97a9c0e52ad7b57090076da83c4fc7bfeefad0a8
Author: darkrain42 at pidgin.im
Date: 2010-02-10T03:32:29
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/0085c32abf29d034d30feef1ffb1d483e316a9a8

Modified files:
        ChangeLog ChangeLog.API libpurple/protocols/bonjour/parser.c
        libpurple/protocols/jabber/parser.c libpurple/xmlnode.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- ChangeLog	f0b9388cb3817f2fe5c053ce4435b8eddbf8451f
+++ ChangeLog	7fe05a0c782ff26ef4f0d99890b664d843e7fd30
@@ -10,6 +10,8 @@ version 2.6.6 (??/??/20??):
 	* 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
============================================================
--- ChangeLog.API	000b1bdf40fb93521eec82742984d8324ad3322f
+++ ChangeLog.API	7a9af0742fec537c6c4eb7c7031b0858437f1ed9
@@ -7,6 +7,12 @@ version 2.6.6 (??/??/2010):
 		  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
============================================================
--- libpurple/protocols/bonjour/parser.c	92eb6a9fce3b1c5818b396694d9c787ea6fae5c4
+++ libpurple/protocols/bonjour/parser.c	44aea64497948e68cb2f7a9a8aefdcc2bcf14191
@@ -49,6 +49,31 @@ parse_from_attrib_and_find_buddy(Bonjour
 	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 @@ bonjour_parser_element_start_libxml(void
 			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);
============================================================
--- libpurple/protocols/jabber/parser.c	f568baef38c737fc7a64fca6efeb545812f7ab7c
+++ libpurple/protocols/jabber/parser.c	92ff195cea10bcd9084fa67882743fb2026c9e5e
@@ -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 @@ jabber_parser_element_start_libxml(void 
 			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);
============================================================
--- libpurple/xmlnode.c	25e8ee46f17d5eb9e8dc16f2d9413507f0dc0e14
+++ libpurple/xmlnode.c	481da12a6cdd695e349a0ed4c7a68bf213895817
@@ -545,6 +545,31 @@ xmlnode_to_formatted_str(const xmlnode *
 	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 @@ xmlnode_parser_element_start_libxml(void
 			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);


More information about the Commits mailing list