Skip to content

Commit

Permalink
lib: var_expand() now expands %{nonexistent} to UNSUPPORTED_VARIABLE_…
Browse files Browse the repository at this point in the history
…nonexistent

Earlier it was expanded to "nonexistent}", which looked more like a bug.
This change hopefully makes it clear enough to understand when a variable isn't
supported.
  • Loading branch information
sirainen authored and GitLab committed Apr 22, 2016
1 parent 0e6e3cc commit 800bb68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/lib/test-var-expand.c
Expand Up @@ -52,7 +52,10 @@ static void test_var_expand_builtin(void)
{ "%50Hv", "1f" },
{ "%50Hw", "2e" },
{ "%50Nv", "25" },
{ "%50Nw", "e" }
{ "%50Nw", "e" },

{ "%{nonexistent}", "UNSUPPORTED_VARIABLE_nonexistent" },
{ "%{nonexistent:default}", "UNSUPPORTED_VARIABLE_nonexistent" },
};
static struct var_expand_table table[] = {
{ 'v', "value", NULL },
Expand Down
6 changes: 4 additions & 2 deletions src/lib/var-expand.c
Expand Up @@ -232,6 +232,8 @@ var_expand_long(const struct var_expand_table *table,
data = "";
value = var_expand_func(func_table, key, data, context);
}
if (value == NULL)
return t_strdup_printf("UNSUPPORTED_VARIABLE_%s", key);
return value;
}

Expand Down Expand Up @@ -325,8 +327,8 @@ void var_expand_with_funcs(string_t *dest, const char *str,
len = end - (str + 1);
var = var_expand_long(table, func_table,
str+1, len, context);
if (var != NULL)
str = end;
i_assert(var != NULL);
str = end;
} else if (table != NULL) {
for (t = table; !TABLE_LAST(t); t++) {
if (t->key == *str) {
Expand Down

0 comments on commit 800bb68

Please sign in to comment.