diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-10 17:37:47 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-04-10 17:37:47 +0200 |
commit | 1817ccdb107ceeaf5c48fe193da5146682c15ca6 (patch) | |
tree | 1b0fecad67841b8cd509468fad8ee6a3d0957fdb | |
parent | aa8e22b035dd669cb47c9237f9c9a917ec6a0ec4 (diff) |
patch 9.1.0301: Vim9: heredoc start may be recognized in stringv9.1.0301
Problem: Vim9: heredoc start may be recognized in string.
Solution: Don't skip to closing bracket for invalid list assignment.
(zeertzjq)
closes: #14472
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r-- | src/testdir/test_let.vim | 15 | ||||
-rw-r--r-- | src/testdir/test_vim9_assign.vim | 14 | ||||
-rw-r--r-- | src/userfunc.c | 11 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 29 insertions, 13 deletions
diff --git a/src/testdir/test_let.vim b/src/testdir/test_let.vim index 1d616350ba..5ee2e9b3c4 100644 --- a/src/testdir/test_let.vim +++ b/src/testdir/test_let.vim @@ -409,10 +409,16 @@ func Test_let_heredoc_fails() endtry try + let [] =<< trim TEXT + TEXT + call assert_report('No exception thrown') + catch /E475:/ + catch + call assert_report('Caught exception: ' .. v:exception) + endtry + + try let [a b c] =<< trim TEXT - change - insert - append TEXT call assert_report('No exception thrown') catch /E475:/ @@ -422,9 +428,6 @@ func Test_let_heredoc_fails() try let [a; b; c] =<< trim TEXT - change - insert - append TEXT call assert_report('No exception thrown') catch /E452:/ diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 0d6d783ed8..0beaa440a8 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -2029,6 +2029,20 @@ def Test_heredoc() END v9.CheckScriptSuccess(lines) + # heredoc start should not be recognized in string + lines =<< trim END + vim9script + def Func() + new + @" = 'bar' + ['foo', @"]->setline("]=<<"->count('=')) + assert_equal(['foo', 'bar'], getline(1, '$')) + bwipe! + enddef + Func() + END + v9.CheckScriptSuccess(lines) + v9.CheckDefFailure(['var lines =<< trim END X', 'END'], 'E488:') v9.CheckDefFailure(['var lines =<< trim END " comment', 'END'], 'E488:') diff --git a/src/userfunc.c b/src/userfunc.c index 015733cdb1..71b39837c7 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -1230,18 +1230,15 @@ get_function_body( int save_sc_version = current_sctx.sc_version; int var_count = 0; int semicolon = 0; - char_u *argend; current_sctx.sc_version = vim9_function ? SCRIPT_VERSION_VIM9 : 1; - argend = skip_var_list(arg, TRUE, &var_count, &semicolon, + arg = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE); - if (argend == NULL) - // Invalid list assignment: skip to closing bracket. - argend = find_name_end(arg, NULL, NULL, FNE_INCL_BR); - arg = skipwhite(argend); + if (arg != NULL) + arg = skipwhite(arg); current_sctx.sc_version = save_sc_version; - if (arg[0] == '=' && arg[1] == '<' && arg[2] =='<') + if (arg != NULL && STRNCMP(arg, "=<<", 3) == 0) { p = skipwhite(arg + 3); while (TRUE) diff --git a/src/version.c b/src/version.c index c256520bb4..2f049c9427 100644 --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 301, +/**/ 300, /**/ 299, |