]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0301: Vim9: heredoc start may be recognized in string v9.1.0301
authorzeertzjq <zeertzjq@outlook.com>
Wed, 10 Apr 2024 15:37:47 +0000 (17:37 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 10 Apr 2024 15:37:47 +0000 (17:37 +0200)
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>
src/testdir/test_let.vim
src/testdir/test_vim9_assign.vim
src/userfunc.c
src/version.c

index 1d616350ba26d99a8af84c3fe8653d8614ffe764..5ee2e9b3c47a26290e52bf68de6fc553aa07a1d7 100644 (file)
@@ -408,11 +408,17 @@ func Test_let_heredoc_fails()
     call assert_report('Caught exception: ' .. v:exception)
   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:/
index 0d6d783ed847d41803f78d8799baff01fe88bc70..0beaa440a8db714bd8f78bab1779c5f68a9e97cc 100644 (file)
@@ -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:')
 
index 015733cdb1a7415872829d2e2ccb471f08da4e67..71b39837c74ce7e72a27c9278da63abe52d8329c 100644 (file)
@@ -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)
index c256520bb452c19614d2175f50dc555494682ed2..2f049c9427d5bfcfe057faa27ff6196c6efe1708 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    301,
 /**/
     300,
 /**/