Filter out ^M (0x0d) characters in incoming messages
This fixes a bug with some centericq versions, reported by Frank Zschockelt.
--- a/mcabber/src/screen.c Wed Jan 10 21:34:18 2007 +0100
+++ b/mcabber/src/screen.c Sat Jan 13 14:27:54 2007 +0100
@@ -1353,9 +1353,7 @@
if (!timestamp) timestamp = time(NULL);
- xtext = ut_expand_tabs(text); // Expand tabs
-
- // XXX Are there other special chars we should filter out?
+ xtext = ut_expand_tabs(text); // Expand tabs and filter out some chars
scr_WriteInWindow(bjid, xtext, timestamp, prefix_flags, FALSE);
--- a/mcabber/src/utils.c Wed Jan 10 21:34:18 2007 +0100
+++ b/mcabber/src/utils.c Sat Jan 13 14:27:54 2007 +0100
@@ -486,22 +486,27 @@
}
// ut_expand_tabs(text)
-// Expand tabs in string text.
-// If there is no tab in the string, a pointer to text is returned (be
-// careful _not_ to free the pointer in this case).
-// If there are some tabs, a new string with expanded chars is returned; this
-// is up to the caller to free this string after use.
+// Expand tabs and filter out some bad chars in string text.
+// If there is no tab and no bad chars in the string, a pointer to text
+// is returned (be careful _not_ to free the pointer in this case).
+// If there are some tabs or bad chars, a new string with expanded chars
+// and no bad chars is returned; this is up to the caller to free this
+// string after use.
char *ut_expand_tabs(const char *text)
{
char *xtext;
char *p, *q;
- guint8 n=0;
+ guint n = 0, bc = 0;
xtext = (char*)text;
for (p=xtext; *p; p++)
- if (*p == '\t') n++;
+ if (*p == '\t')
+ n++;
+ else if (*p == '\x0d')
+ bc++;
+ // XXX Are there other special chars we should filter out?
- if (!n)
+ if (!n && !bc)
return (char*)text;
xtext = g_new(char, strlen(text) + 1 + 8*n);
@@ -510,7 +515,7 @@
do {
if (*p == '\t') {
do { *q++ = ' '; } while ((q-xtext)%8);
- } else {
+ } else if (*p != '\x0d') {
*q++ = *p;
}
} while (*p++);