diff --git a/src/lib/test-var-expand.c b/src/lib/test-var-expand.c index 370199cb26..d3f248a9ed 100644 --- a/src/lib/test-var-expand.c +++ b/src/lib/test-var-expand.c @@ -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 }, diff --git a/src/lib/var-expand.c b/src/lib/var-expand.c index fee44c9c4b..5d06cebee0 100644 --- a/src/lib/var-expand.c +++ b/src/lib/var-expand.c @@ -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; } @@ -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) {