]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: var_expand*() - Ignore modifiers for unknown variables
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 11 Feb 2020 09:20:43 +0000 (11:20 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 8 Apr 2020 07:54:32 +0000 (07:54 +0000)
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
src/lib/var-expand.c

index 656b647407c1fa78f11b6991564bd83fbda16836..bae4277f5dd4600c5b024b88e3b027797b46e60e 100644 (file)
@@ -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 },
index 465dca6e138a1ee9344a1774490cabc6ab3ad25f..4d785f068001d9db61f3a7e7a58e36e8c061e3f7 100644 (file)
@@ -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);