diff libpurple/util.c @ 27393:57fdb7853fc7

Create a purple_markup_escape_text() function and use it in one place in oscar. This function is identical to glib's g_markup_escape_text() except that it does not replace ' with ' ' is not a valid HTML entity in HTML 4, and IE7 displays it as the raw characters and not as an apostrophe. gtk of course displays it as an apostrophe, but gtk seems to have no problems with unescaped apostrophes I really don't know why g_markup_escape_text() escapes this character. So this change should not affect Pidgin at all, and it should help any user of libpurple who displays our HTML in IE (or possibly other web browsers--I'm not sure how webkit handles ') Are people ok with this change? We should probably change a lot of other places to use this function instead of the glib one. Basically anything that converts text to html should use this. I think anything that escapes XML should continue using g_markup_escape_text(). And entry_key_pressed() in Finch can be changed to use this instead of g_markup_escape_text() and purple_strreplace()
author Mark Doliner <mark@kingant.net>
date Mon, 06 Jul 2009 23:46:56 +0000
parents 6275df9d2d62
children 52298a298260
line wrap: on
line diff
--- a/libpurple/util.c	Mon Jul 06 23:24:37 2009 +0000
+++ b/libpurple/util.c	Mon Jul 06 23:46:56 2009 +0000
@@ -942,6 +942,77 @@
  * Markup Functions
  **************************************************************************/
 
+/*
+ * This function is stolen from glib's gmarkup.c and modified to not
+ * replace ' with &apos;
+ */
+static void append_escaped_text(GString *str,
+		const gchar *text, gssize length)
+{
+	const gchar *p;
+	const gchar *end;
+	gunichar c;
+
+	p = text;
+	end = text + length;
+
+	while (p != end)
+	{
+		const gchar *next;
+		next = g_utf8_next_char (p);
+
+		switch (*p)
+		{
+			case '&':
+				g_string_append (str, "&amp;");
+				break;
+
+			case '<':
+				g_string_append (str, "&lt;");
+				break;
+
+			case '>':
+				g_string_append (str, "&gt;");
+				break;
+
+			case '"':
+				g_string_append (str, "&quot;");
+				break;
+
+			default:
+				c = g_utf8_get_char (p);
+				if ((0x1 <= c && c <= 0x8) ||
+						(0xb <= c && c <= 0xc) ||
+						(0xe <= c && c <= 0x1f) ||
+						(0x7f <= c && c <= 0x84) ||
+						(0x86 <= c && c <= 0x9f))
+					g_string_append_printf (str, "&#x%x;", c);
+				else
+					g_string_append_len (str, p, next - p);
+				break;
+		}
+
+		p = next;
+	}
+}
+
+/* This function is stolen from glib's gmarkup.c */
+gchar *purple_markup_escape_text(const gchar *text, gssize length)
+{
+	GString *str;
+
+	g_return_val_if_fail(text != NULL, NULL);
+
+	if (length < 0)
+		length = strlen(text);
+
+	/* prealloc at least as long as original text */
+	str = g_string_sized_new(length);
+	append_escaped_text(str, text, length);
+
+	return g_string_free(str, FALSE);
+}
+
 const char *
 purple_markup_unescape_entity(const char *text, int *length)
 {