From e08ca174888da9d11742e2b08501a1449ebe5b7d Mon Sep 17 00:00:00 2001 From: ali Date: Sat, 3 Aug 2019 09:19:20 +0000 Subject: [PATCH] evas_textblock: markup text: improve handling invalide escape characters Improve handling invalid escape characters. (*) When '&' character founded in Markup text. Old Behavior : Any text after '&' (if it is not escape), all text will be discarded New Behavior : Any text after '&' (if it is not escape), will be processes as normal plain text. Example: Markup Text : Hello X & Y & Z 1 2 3 Old output : Hello New output : Hello X & Y & Z 1 2 3 This is related to T8077 Reviewed-by: Cedric BAIL Differential Revision: https://phab.enlightenment.org/D9489 --- src/lib/evas/canvas/evas_object_textblock.c | 18 ++++++++++++++++ src/tests/evas/evas_test_textblock.c | 24 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 6299e3f195..433597fa27 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -8144,6 +8144,12 @@ _evas_object_textblock_text_markup_prepend(Eo *eo_obj, _prepend_escaped_char(cur, esc_start, esc_end + 1); esc_start = esc_end = NULL; } + else if (*p == 0 && esc_start) /* escape start with no end, append it as text */ + { + _prepend_text_run(cur, esc_start, p); + esc_start = esc_end = NULL; + s = NULL; + } else if (*p == 0) { _prepend_text_run(cur, s, p); @@ -8154,6 +8160,12 @@ _evas_object_textblock_text_markup_prepend(Eo *eo_obj, } if (*p == '<') { + if (esc_start) /* escape start with no end, append it as text */ + { + _prepend_text_run(cur, esc_start, p); + esc_start = esc_end = NULL; + s = NULL; + } if (!esc_start) { /* Append the text prior to this to the textblock and mark @@ -8174,6 +8186,12 @@ _evas_object_textblock_text_markup_prepend(Eo *eo_obj, } else if (*p == '&') { + if (esc_start) /* escape start with no end, append it as text */ + { + _prepend_text_run(cur, esc_start, p); + esc_start = esc_end = NULL; + s = NULL; + } if (!tag_start) { /* Append the text prior to this to the textblock and mark diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c index ef81ae3172..f61574c065 100644 --- a/src/tests/evas/evas_test_textblock.c +++ b/src/tests/evas/evas_test_textblock.c @@ -4654,6 +4654,29 @@ EFL_START_TEST(efl_canvas_text_markup) } EFL_END_TEST +EFL_START_TEST(efl_canvas_text_markup_invalid_escape) +{ + START_EFL_CANVAS_TEXT_TEST(); + + char * text1 = "Hello"; + char * text2 = "Hello&123"; + char * text3 = "Hello&123&456"; + Evas_Coord fw1, fw2, fw3; + + efl_text_markup_set(txt,text1); + efl_canvas_text_size_native_get(txt, &fw1, NULL); + efl_text_markup_set(txt,text2); + efl_canvas_text_size_native_get(txt, &fw2, NULL); + fail_if(fw2 <= fw1); + efl_text_markup_set(txt,text3); + efl_canvas_text_size_native_get(txt, &fw3, NULL); + fail_if(fw3 <= fw2); + + END_EFL_CANVAS_TEXT_TEST(); +} +EFL_END_TEST + + EFL_START_TEST(efl_text_font) { START_EFL_CANVAS_TEXT_TEST(); @@ -4715,6 +4738,7 @@ void evas_test_textblock(TCase *tc) tcase_add_test(tc, efl_text); tcase_add_test(tc, efl_canvas_text_cursor); tcase_add_test(tc, efl_canvas_text_markup); + tcase_add_test(tc, efl_canvas_text_markup_invalid_escape); tcase_add_test(tc, efl_text_font); }