pidgin: 16a4a4bd: Create a purple_markup_escape_text() fun...
markdoliner at pidgin.im
markdoliner at pidgin.im
Mon Jul 6 19:50:22 EDT 2009
-----------------------------------------------------------------
Revision: 16a4a4bd2cbd99767c01c86a94cae03a5aa8c004
Ancestor: a005829cf6a7f1c1e1d08a9ed295691a6f711a33
Author: markdoliner at pidgin.im
Date: 2009-07-06T23:46:56
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/16a4a4bd2cbd99767c01c86a94cae03a5aa8c004
Modified files:
libpurple/protocols/oscar/oscar.c libpurple/util.c
libpurple/util.h
ChangeLog:
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()
-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/oscar.c 8340200845138bf2517b98164b53a7114244fc4f
+++ libpurple/protocols/oscar/oscar.c d59497d11d676fb587c728c6bc4d6dfdc85a2d79
@@ -2222,7 +2222,7 @@ static int purple_parse_oncoming(OscarDa
message = oscar_encoding_to_utf8(account, info->status_encoding,
info->status, info->status_len);
- tmp2 = tmp = (message ? g_markup_escape_text(message, -1) : NULL);
+ tmp2 = tmp = (message ? purple_markup_escape_text(message, -1) : NULL);
if (strcmp(status_id, OSCAR_STATUS_ID_AVAILABLE) == 0) {
if (info->itmsurl_encoding && info->itmsurl && info->itmsurl_len)
============================================================
--- libpurple/util.c 771b547b7050b66dd8e5500bf1145db9f144de63
+++ libpurple/util.c ff376676398e1d9e6157a03e9192f5f460c86ba3
@@ -942,6 +942,77 @@ purple_str_to_time(const char *timestamp
* Markup Functions
**************************************************************************/
+/*
+ * This function is stolen from glib's gmarkup.c and modified to not
+ * replace ' with '
+ */
+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, "&");
+ break;
+
+ case '<':
+ g_string_append (str, "<");
+ break;
+
+ case '>':
+ g_string_append (str, ">");
+ break;
+
+ case '"':
+ g_string_append (str, """);
+ 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)
{
============================================================
--- libpurple/util.h d492c996a474c79715d23f4a9bebb3d8cb9c788a
+++ libpurple/util.h 8fcdccad79dbddaf846abed37d0ed78abe65bcc7
@@ -415,6 +415,17 @@ time_t purple_str_to_time(const char *ti
/*@{*/
/**
+ * Escapes special characters in a plain-text string so they display
+ * correctly as HTML. For example, & is replaced with & and < is
+ * replaced with <
+ *
+ * This is exactly the same as g_markup_escape_text(), except that it
+ * does not change ' to ' because ' is not a valid HTML 4 entity,
+ * and is displayed literally in IE7.
+ */
+gchar *purple_markup_escape_text(const gchar *text, gssize length);
+
+/**
* Finds an HTML tag matching the given name.
*
* This locates an HTML tag's start and end, and stores its attributes
More information about the Commits
mailing list