[PATCH (3.4)] cfg_lexer: Drop quotes when expanding a backtick, and already quoted
In case we're expanding a backtick while we're already in a quoted string, and the backtick starts with a '"', drop the extra quotes. This allows blocks like: block source s_logfile (filename("messages")) { file("/var/log/`filename`"); }; source s_example { s_logfile(filename("logfile.log")); }; To work properly, and result in file("/var/log/logfile.log"); Reported-by: Eric Berggren <eric_berggren@apple.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu> --- lib/cfg-lexer.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/cfg-lexer.c b/lib/cfg-lexer.c index fbce432..b1c7c93 100644 --- a/lib/cfg-lexer.c +++ b/lib/cfg-lexer.c @@ -156,12 +156,18 @@ gchar * cfg_lexer_subst_args(CfgArgs *globals, CfgArgs *defs, CfgArgs *args, gchar *cptr, gsize *length) { gboolean backtick = FALSE; + gboolean in_string = FALSE; gchar *p, *ref_start = cptr; GString *result = g_string_sized_new(32); p = cptr; while (*p) { + if (!backtick && (*p) == '"') + { + in_string = !in_string; + } + if (!backtick && (*p) == '`') { /* start of reference */ @@ -195,7 +201,12 @@ cfg_lexer_subst_args(CfgArgs *globals, CfgArgs *defs, CfgArgs *args, gchar *cptr arg = NULL; *p = '`'; - g_string_append(result, arg ? arg : ""); + if (in_string && arg && arg[0] == '"') + { + g_string_append_len(result, &arg[1], strlen(arg) - 2); + } + else + g_string_append(result, arg ? arg : ""); } } else if (!backtick) -- 1.7.10.4
participants (1)
-
Gergely Nagy