From 5598afae699eea7b581094df6c0d084b08c014e1 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 11 Feb 2020 11:20:43 +0200 Subject: [PATCH] lib: var_expand*() - Ignore modifiers for unknown variables So for example %M{asdf} will return UNSUPPORTED_VARIABLE_asdf instead of MD5 hash of it, which might not be so obvious that it's not working correctly. --- src/lib/test-var-expand.c | 3 ++- src/lib/var-expand.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/test-var-expand.c b/src/lib/test-var-expand.c index 656b647407..bae4277f5d 100644 --- a/src/lib/test-var-expand.c +++ b/src/lib/test-var-expand.c @@ -58,8 +58,9 @@ static void test_var_expand_builtin(void) { "%50Nw", "e", 1 }, { "%{nonexistent}", "UNSUPPORTED_VARIABLE_nonexistent", 0 }, - { "%{nonexistent:default}", "UNSUPPORTED_VARIABLE_nonexistent", 0 }, + { "%1.2M{nonexistent:default}", "UNSUPPORTED_VARIABLE_nonexistent", 0 }, { "%x", "UNSUPPORTED_VARIABLE_x", 0 }, + { "%5Mm", "UNSUPPORTED_VARIABLE_m", 0 }, }; static const struct var_expand_table table[] = { { 'v', "value", NULL }, diff --git a/src/lib/var-expand.c b/src/lib/var-expand.c index 465dca6e13..4d785f0680 100644 --- a/src/lib/var-expand.c +++ b/src/lib/var-expand.c @@ -589,7 +589,9 @@ int var_expand_with_funcs(string_t *dest, const char *str, if (final_ret > ret) final_ret = ret; - if (var != NULL) { + if (ret <= 0) + str_append(dest, var); + else { for (i = 0; i < modifier_count; i++) var = modifier[i](var, &ctx); -- 2.47.3