pidgin: c61d5559: Hmm, g_unichar_isgraph is too restrictiv...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Thu Aug 27 20:06:48 EDT 2009


-----------------------------------------------------------------
Revision: c61d5559bb5cfd55defb3613015e9118dbc2184e
Ancestor: 18135201f43ac87c932feae03881d46e30d93030
Author: darkrain42 at pidgin.im
Date: 2009-08-27T23:59:30
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c61d5559bb5cfd55defb3613015e9118dbc2184e

Modified files:
        libpurple/util.c libpurple/util.h

ChangeLog: 

Hmm, g_unichar_isgraph is too restrictive in the characters allowed (it munges \t). Change purple_utf8_strip_unprintables to simply remove ASCII control characters instead.

-------------- next part --------------
============================================================
--- libpurple/util.c	c4d036a2d4968d1873234c4e0f034c4ee84b1055
+++ libpurple/util.c	0b8a49e32d13809bf5c1c4c909d29cfc64c0dd51
@@ -4660,17 +4660,11 @@ purple_utf8_strip_unprintables(const gch
 	g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL);
 
 	workstr = iter = g_new(gchar, strlen(str) + 1);
-	while (*str) {
-		gunichar c = g_utf8_get_char(str);
-		const gchar *next = g_utf8_next_char(str);
-		size_t len = next - str;
-
-		if (g_unichar_isprint(c)) {
-			memcpy(iter, str, len);
-			iter += len;
+	for ( ; *str; ++str) {
+		if (*str >= 0x20 || *str == 0x09 || *str == 0x0a || *str == 0x0d) {
+			*iter = *str;
+			++iter;
 		}
-
-		str = next;
 	}
 
 	/* nul-terminate the new string */
============================================================
--- libpurple/util.h	15314a02d4888bf6c4fffdbfc4b79989a276b84e
+++ libpurple/util.h	fe601b6313642f6948d3cc89aff32bbd8ff08454
@@ -1286,16 +1286,14 @@ gchar *purple_utf8_salvage(const char *s
 /**
  * Removes unprintable characters from a UTF-8 string. These characters
  * (in particular low-ASCII characters) are invalid in XML 1.0 and thus
- * are not allowed in XMPP and are rejected by libxml2 by default. This
- * function uses g_unichar_isprint to determine what characters should
- * be stripped. The returned string must be freed by the caller.
+ * are not allowed in XMPP and are rejected by libxml2 by default.
  *
+ * The returned string must be freed by the caller.
+ *
  * @param str A valid UTF-8 string.
  *
  * @return A newly allocated UTF-8 string without the unprintable characters.
  * @since 2.6.0
- *
- * @see g_unichar_isprint
  */
 gchar *purple_utf8_strip_unprintables(const gchar *str);
 


More information about the Commits mailing list