Skip to content

Commit

Permalink
lib: var-expand - handle \{ and \} correctly
Browse files Browse the repository at this point in the history
Do not treat these as embedded braces
  • Loading branch information
cmouse authored and villesavolainen committed Feb 5, 2018
1 parent b30d6bc commit c26fd9f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib/var-expand.c
Expand Up @@ -544,8 +544,17 @@ void var_expand_with_funcs(string_t *dest, const char *str,
/* %{long_key} */
const char *error;
unsigned int ctr = 1;
bool escape = FALSE;
end = str;
while(*++end != '\0' && ctr > 0) {
if (!escape && *end == '\\') {
escape = TRUE;
continue;
}
if (escape) {
escape = FALSE;
continue;
}
if (*end == '{') ctr++;
if (*end == '}') ctr--;
}
Expand Down Expand Up @@ -644,6 +653,14 @@ var_get_key_range_full(const char *str, unsigned int *idx_r,
/* long key */
*idx_r = ++i;
for (; str[i] != '\0'; i++) {
if (!escape && str[i] == '\\') {
escape = TRUE;
continue;
}
if (escape) {
escape = FALSE;
continue;
}
if (str[i] == '{')
depth++;
if (str[i] == '}') {
Expand Down

0 comments on commit c26fd9f

Please sign in to comment.