0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.2.4840: heredoc expression evaluated even when skipping

Problem:    Heredoc expression evaluated even when skipping.
Solution:   Don't evaluate when "skip" is set. (closes #10306)
This commit is contained in:
Bram Moolenaar
2022-04-28 16:51:41 +01:00
parent 0a748d9184
commit 05c7f5d3d0
3 changed files with 16 additions and 1 deletions

View File

@@ -835,7 +835,7 @@ heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int vim9compile)
} }
else else
{ {
if (evalstr) if (evalstr && !eap->skip)
{ {
str = eval_all_expr_in_str(str); str = eval_all_expr_in_str(str);
if (str == NULL) if (str == NULL)

View File

@@ -509,20 +509,24 @@ func Test_let_heredoc_eval()
let c = "abc`=str`d" let c = "abc`=str`d"
END END
call assert_equal(['let a = 15', 'let b = 6 + 6', '', 'let c = "abcd"'], code) call assert_equal(['let a = 15', 'let b = 6 + 6', '', 'let c = "abcd"'], code)
let $TESTVAR = "Hello" let $TESTVAR = "Hello"
let code =<< eval trim END let code =<< eval trim END
let s = "`=$TESTVAR`" let s = "`=$TESTVAR`"
END END
call assert_equal(['let s = "Hello"'], code) call assert_equal(['let s = "Hello"'], code)
let code =<< eval END let code =<< eval END
let s = "`=$TESTVAR`" let s = "`=$TESTVAR`"
END END
call assert_equal([' let s = "Hello"'], code) call assert_equal([' let s = "Hello"'], code)
let a = 10 let a = 10
let data =<< eval END let data =<< eval END
`=a` `=a`
END END
call assert_equal(['10'], data) call assert_equal(['10'], data)
let x = 'X' let x = 'X'
let code =<< eval trim END let code =<< eval trim END
let a = `abc` let a = `abc`
@@ -530,12 +534,14 @@ END
let c = ` let c = `
END END
call assert_equal(['let a = `abc`', 'let b = X', 'let c = `'], code) call assert_equal(['let a = `abc`', 'let b = X', 'let c = `'], code)
let code = 'xxx' let code = 'xxx'
let code =<< eval trim END let code =<< eval trim END
let n = `=5 + let n = `=5 +
6` 6`
END END
call assert_equal('xxx', code) call assert_equal('xxx', code)
let code =<< eval trim END let code =<< eval trim END
let n = `=min([1, 2]` + `=max([3, 4])` let n = `=min([1, 2]` + `=max([3, 4])`
END END
@@ -562,6 +568,13 @@ END
LINES LINES
call v9.CheckScriptFailure(lines, 'E15:') call v9.CheckScriptFailure(lines, 'E15:')
" skipped heredoc
if 0
let msg =<< trim eval END
n is: `=n`
END
endif
" Test for sourcing a script containing a heredoc with invalid expression. " Test for sourcing a script containing a heredoc with invalid expression.
" Variable assignment should fail, if expression evaluation fails " Variable assignment should fail, if expression evaluation fails
new new

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4840,
/**/ /**/
4839, 4839,
/**/ /**/