Problem: String interpolation fails when not evaluating.
Solution: Skip the expression when not evaluating. (closes #10398)
/*
* 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;
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;
}
}
// 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);
int get_spellword(list_T *list, char_u **pp);
void prepare_vimvar(int idx, typval_T *save_tv);
void restore_vimvar(int idx, typval_T *save_tv);
-char_u *eval_one_expr_in_str(char_u *p, garray_T *gap);
+char_u *eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate);
char_u *eval_all_expr_in_str(char_u *str);
list_T *heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int vim9compile);
void ex_var(exarg_T *eap);
->split($'x{x}x')
->map((_, v: string) => v =~ 'bar')
assert_equal([false, true, false], vl)
+
+ # interpolated string in a lambda
+ lines =<< trim END
+ assert_equal(['gnome-256color', 'xterm-256color'], ['gnome', 'xterm']
+ ->map((_, term: string) => $'{term}-256color'))
+ END
+ v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_expr8_vimvar()
++*arg;
break;
}
- p = eval_one_expr_in_str(*arg, &ga);
+ p = eval_one_expr_in_str(*arg, &ga, evaluate);
if (p == NULL)
{
ret = FAIL;
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 4934,
/**/
4933,
/**/