Evas textblock: Filter out illegal chars from format.
authortasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 19 Jan 2012 08:41:37 +0000 (08:41 +0000)
committertasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 19 Jan 2012 08:41:37 +0000 (08:41 +0000)
This really just filters them out. The solution is not complete, nor is
it the best one. But this fixes the bugs for the meanwhile.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@67327 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/canvas/evas_object_textblock.c
src/tests/evas_test_textblock.c

index 29a996f..77ffe2c 100644 (file)
@@ -4930,6 +4930,7 @@ evas_object_textblock_text_markup_prepend(Evas_Textblock_Cursor *cur, const char
          * NULL is reached. */
         for (;;)
           {
+             size_t text_len;
              /* If we got to the end of string or just finished/started tag
               * or escape sequence handling. */
              if ((*p == 0) ||
@@ -5008,14 +5009,19 @@ evas_object_textblock_text_markup_prepend(Evas_Textblock_Cursor *cur, const char
                }
              /* Unicode object replcament char */
              else if (!strncmp(_REPLACEMENT_CHAR_UTF8, p,
-                      strlen(_REPLACEMENT_CHAR_UTF8)))
+                      text_len = strlen(_REPLACEMENT_CHAR_UTF8)) ||
+                   !strncmp(_NEWLINE_UTF8, p,
+                      text_len = strlen(_NEWLINE_UTF8)) ||
+                   !strncmp(_PARAGRAPH_SEPARATOR_UTF8, p,
+                      text_len = strlen(_PARAGRAPH_SEPARATOR_UTF8)))
                {
                   /*FIXME: currently just remove them, maybe do something
                    * fancier in the future, atm it breaks if this char
                    * is inside <> */
                   _prepend_text_run(cur, s, p);
-                  p += 2; /* it's also advanced later in this loop need +3
-                           * in total*/
+                  /* it's also advanced later in this loop need +text_len
+                     in total*/
+                  p += text_len - 1;
                   s = p + 1; /* One after the end of the replacement char */
                }
              p++;
index a02f469..4f4fb95 100644 (file)
@@ -1430,6 +1430,23 @@ START_TEST(evas_textblock_editing)
    evas_textblock_cursor_paragraph_first(cur);
    fail_if(evas_textblock_cursor_paragraph_next(cur));
 
+   /* Insert illegal characters inside the format. */
+   evas_object_textblock_text_markup_set(tb, "a\n");
+   evas_textblock_cursor_pos_set(cur, 1);
+   evas_textblock_cursor_content_get(cur);
+
+   evas_object_textblock_text_markup_set(tb, "a\t");
+   evas_textblock_cursor_pos_set(cur, 1);
+   evas_textblock_cursor_content_get(cur);
+
+   evas_object_textblock_text_markup_set(tb, "a\xEF\xBF\xBC");
+   evas_textblock_cursor_pos_set(cur, 1);
+   evas_textblock_cursor_content_get(cur);
+
+   evas_object_textblock_text_markup_set(tb, "a\xE2\x80\xA9");
+   evas_textblock_cursor_pos_set(cur, 1);
+   evas_textblock_cursor_content_get(cur);
+
    /* FIXME: Also add text appending/prepending */
 
    END_TB_TEST();