Skip to content

Instantly share code, notes, and snippets.

@rlaager
Created October 11, 2013 20:51
Show Gist options
  • Save rlaager/6941858 to your computer and use it in GitHub Desktop.
Save rlaager/6941858 to your computer and use it in GitHub Desktop.
A patch to irchelper which strips control characters.
diff --git a/irchelper/irchelper.c b/irchelper/irchelper.c
--- a/irchelper/irchelper.c
+++ b/irchelper/irchelper.c
@@ -781,18 +781,44 @@
if ((node = (PurpleBlistNode *)purple_blist_find_chat(account, name)) != NULL)
{
const char *last_topic = purple_blist_node_get_string(node, PLUGIN_ID "_topic");
+ char *topic_cleaned = g_malloc(strlen(topic));
+ const char *t = topic;
+ char *tc = topic_cleaned;
+
+ /* Strip invalid XML characters to work around libpurple using
+ * g_markup_escape_text() which is XML 1.1 in files with an XML 1.0
+ * declaration (and libxml2, which doesn't appear to support XML 1.1). */
+ for ( ; *t ; t++)
+ {
+ if ( *t == 0x0009 ||
+ *t == 0x000a ||
+ *t == 0x000d ||
+ (*t >= 0x0020 && *t <= 0x007e) ||
+ *t == 0x0085 ||
+ (*t >= 0x00a0 && *t <= 0xd7ff) ||
+ (*t >= 0xe000 && *t <= 0xfdcf) ||
+ (*t >= 0xfde0 && !((*t & 0xFFFE) == 0xFFFE || (*t & 0xFFFF) == 0xFFFF))
+ )
+ {
+ *tc = *t;
+ tc++;
+ }
+ }
+ *tc = '\0';
/* If we saw this the last time we joined, suppress it. */
- if (last_topic != NULL && strcmp(topic, last_topic) == 0)
+ if (last_topic != NULL && strcmp(topic_cleaned, last_topic) == 0)
{
g_free(name_escaped);
g_free(topic_escaped);
g_free(topic_linkified);
+ g_free(topic_cleaned);
return TRUE;
}
else
- purple_blist_node_set_string(node, PLUGIN_ID "_topic", topic);
+ purple_blist_node_set_string(node, PLUGIN_ID "_topic", topic_cleaned);
+ g_free(topic_cleaned);
}
}
g_free(name_escaped);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment