diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-06-08 23:14:22 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-06-08 23:43:59 +0800 |
commit | 03c709802eebcacdabe2c2738e166da9f4cb1f31 (patch) | |
tree | 607a55c71713c24ead95981886e9d2ce55df5916 | |
parent | 8b8e9567d5a5d44bbb565013e1b7856f21ab1c5f (diff) | |
download | gsoc2013-empathy-03c709802eebcacdabe2c2738e166da9f4cb1f31.tar gsoc2013-empathy-03c709802eebcacdabe2c2738e166da9f4cb1f31.tar.gz gsoc2013-empathy-03c709802eebcacdabe2c2738e166da9f4cb1f31.tar.bz2 gsoc2013-empathy-03c709802eebcacdabe2c2738e166da9f4cb1f31.tar.lz gsoc2013-empathy-03c709802eebcacdabe2c2738e166da9f4cb1f31.tar.xz gsoc2013-empathy-03c709802eebcacdabe2c2738e166da9f4cb1f31.tar.zst gsoc2013-empathy-03c709802eebcacdabe2c2738e166da9f4cb1f31.zip |
empathy_string_replace_escaped: remove '\r' (#620903)
-rw-r--r-- | libempathy-gtk/empathy-string-parser.c | 16 | ||||
-rw-r--r-- | tests/empathy-parser-test.c | 4 |
2 files changed, 19 insertions, 1 deletions
diff --git a/libempathy-gtk/empathy-string-parser.c b/libempathy-gtk/empathy-string-parser.c index 5c3fb1972..52c726c69 100644 --- a/libempathy-gtk/empathy-string-parser.c +++ b/libempathy-gtk/empathy-string-parser.c @@ -185,9 +185,23 @@ empathy_string_replace_escaped (const gchar *text, { GString *string = user_data; gchar *escaped; + guint i; + gssize escaped_len, old_len; escaped = g_markup_escape_text (text, len); - g_string_append (string, escaped); + escaped_len = strlen (escaped); + + /* Allocate more space to string (we really need a g_string_extend...) */ + old_len = string->len; + g_string_set_size (string, old_len + escaped_len); + g_string_truncate (string, old_len); + + /* Remove '\r' */ + for (i = 0; i < escaped_len; i++) { + if (escaped[i] != '\r') + g_string_append_c (string, escaped[i]); + } + g_free (escaped); } diff --git a/tests/empathy-parser-test.c b/tests/empathy-parser-test.c index 8e4c15a66..5713d967c 100644 --- a/tests/empathy-parser-test.c +++ b/tests/empathy-parser-test.c @@ -78,6 +78,10 @@ test_parsers (void) ":)http://foo.com", "[:)][http://foo.com]", "a :) b http://foo.com c :( d www.test.com e", "a [:)] b [http://foo.com] c [:(] d [www.test.com] e", + /* '\r' should be stripped */ + "badger\n\rmushroom", "badger\nmushroom", + "badger\r\nmushroom", "badger\nmushroom", + /* FIXME: Known issue: Brackets should be counted by the parser */ //"Foo www.bar.com/test(123)", "Foo [www.bar.com/test(123)]", //"Foo (www.bar.com/test(123))", "Foo ([www.bar.com/test(123)])", |