summaryrefslogtreecommitdiffstats
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-10 18:11:43 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-10 18:11:43 +0100
commit70c41241c2701f26a99085e433925a206ca265a3 (patch)
tree1afeaeb49dfc47199313bf397955519a5f598572 /src/evalvars.c
parentdf6e0e46c55c9c6d788f94482a8858c0f31391f4 (diff)
patch 8.2.4934: string interpolation fails when not evaluatingv8.2.4934
Problem: String interpolation fails when not evaluating. Solution: Skip the expression when not evaluating. (closes #10398)
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index d8ee216084..e83c50dff2 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -605,10 +605,11 @@ list_script_vars(int *first)
/*
* Evaluate one Vim expression {expr} in string "p" and append the
* resulting string to "gap". "p" points to the opening "{".
+ * When "evaluate" is FALSE only skip over the expression.
* Return a pointer to the character after "}", NULL for an error.
*/
char_u *
-eval_one_expr_in_str(char_u *p, garray_T *gap)
+eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate)
{
char_u *block_start = skipwhite(p + 1); // skip the opening {
char_u *block_end = block_start;
@@ -627,13 +628,16 @@ eval_one_expr_in_str(char_u *p, garray_T *gap)
semsg(_(e_missing_close_curly_str), p);
return NULL;
}
- *block_end = NUL;
- expr_val = eval_to_string(block_start, TRUE);
- *block_end = '}';
- if (expr_val == NULL)
- return NULL;
- ga_concat(gap, expr_val);
- vim_free(expr_val);
+ if (evaluate)
+ {
+ *block_end = NUL;
+ expr_val = eval_to_string(block_start, TRUE);
+ *block_end = '}';
+ if (expr_val == NULL)
+ return NULL;
+ ga_concat(gap, expr_val);
+ vim_free(expr_val);
+ }
return block_end + 1;
}
@@ -691,7 +695,7 @@ eval_all_expr_in_str(char_u *str)
}
// Evaluate the expression and append the result.
- p = eval_one_expr_in_str(p, &ga);
+ p = eval_one_expr_in_str(p, &ga, TRUE);
if (p == NULL)
{
ga_clear(&ga);