From 5746d15cf86540ce758fe9821b1362ab7007c91b Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 13 Dec 2014 12:12:34 +0100 Subject: [PATCH] Handle escaped : in clickable areas. Fixes #92 --- bar.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bar.c b/bar.c index 17e4004..540c078 100644 --- a/bar.c +++ b/bar.c @@ -249,6 +249,7 @@ bool area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x, const int align, const int button) { char *p = str; + char *trail; area_t *a = &astack.slot[astack.pos]; if (astack.pos == N) { @@ -286,7 +287,9 @@ area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x return true; } - char *trail = strchr(++p, ':'); + /* Found the closing : and check if it's just an escaped one */ + for (trail = strchr(++p, ':'); trail && trail[-1] == '\\'; trail = strchr(trail + 1, ':')) + ; /* Find the trailing : and make sure it's whitin the formatting block, also reject empty commands */ if (!trail || p == trail || trail > optend) { @@ -296,6 +299,15 @@ area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x *trail = '\0'; + /* Sanitize the user command by unescaping all the : */ + for (char *needle = p; *needle; needle++) { + int delta = trail - &needle[1]; + if (needle[0] == '\\' && needle[1] == ':') { + memmove(&needle[0], &needle[1], delta); + needle[delta] = 0; + } + } + /* This is a pointer to the string buffer allocated in the main */ a->cmd = p; a->align = align;