From 2d4ba9e8dd0fb335ce30bce4425d273db5d6f7e7 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 27 Jan 2014 15:14:32 +0000 Subject: [PATCH] Edje entry: Fix anchor href parsing. It should now correctly work with arguments surrounded with either quotes or spaces. --- src/lib/edje/edje_entry.c | 46 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/lib/edje/edje_entry.c b/src/lib/edje/edje_entry.c index 40592af05a..5754a578ab 100644 --- a/src/lib/edje/edje_entry.c +++ b/src/lib/edje/edje_entry.c @@ -1037,6 +1037,48 @@ _anchors_clear(Evas_Textblock_Cursor *c EINA_UNUSED, Evas_Object *o EINA_UNUSED, } } +/* FIXME: This is horrible. It's just a copy&paste (with some adjustments) + * from textblock. I didn't want to introduce any non-API links between the + * libs so I just copied it. Should have been handled differently. */ +static char * +_anchor_format_parse(const char *item) +{ + const char *start, *end; + char *tmp; + size_t len; + + start = strchr(item, '='); + start++; /* Advance after the '=' */ + /* If we can find a quote as the first non-space char, + * our new delimiter is a quote, not a space. */ + while (*start == ' ') + start++; + + if (*start == '\'') + { + start++; + end = strchr(start, '\''); + while ((end) && (end > start) && (end[-1] == '\\')) + end = strchr(end + 1, '\''); + } + else + { + end = strchr(start, ' '); + while ((end) && (end > start) && (end[-1] == '\\')) + end = strchr(end + 1, ' '); + } + + /* Null terminate before the spaces */ + if (end) len = end - start; + else len = strlen(start); + + tmp = malloc(len); + strncpy(tmp, start, len); + tmp[len] = '\0'; + + return tmp; +} + static void _anchors_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) { @@ -1063,7 +1105,7 @@ _anchors_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) p = strstr(s, "href="); if (p) { - an->name = strdup(p + 5); + an->name = _anchor_format_parse(p); } en->anchors = eina_list_append(en->anchors, an); an->start = evas_object_textblock_cursor_new(o); @@ -1114,7 +1156,7 @@ _anchors_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en) p = strstr(s, "href="); if (p) { - an->name = strdup(p + 5); + an->name = _anchor_format_parse(p); } en->anchors = eina_list_append(en->anchors, an); an->start = evas_object_textblock_cursor_new(o);