Handle escaped : in clickable areas. Fixes #92

This commit is contained in:
LemonBoy 2014-12-13 12:12:34 +01:00
parent 3c2b9ff150
commit 5746d15cf8
1 changed files with 13 additions and 1 deletions

14
bar.c
View File

@ -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;