]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1074: Strange error when heredoc marker starts with "trim" v9.1.1074
authorzeertzjq <zeertzjq@outlook.com>
Mon, 3 Feb 2025 17:56:16 +0000 (18:56 +0100)
committerChristian Brabandt <cb@256bit.org>
Mon, 3 Feb 2025 17:56:16 +0000 (18:56 +0100)
Problem:  Strange error when heredoc marker starts with "trim".
Solution: Check for whitespace after "trim" or "eval" (zeertzjq)

For :python3 etc., a heredoc marker that starts with a lower-case letter
is valid, and when it starts with "trim" it works in a script but not in
a function, and this PR makes it works in a function.
For :let, a heredoc marker that starts with a lower-case letter is not
valid, but when it starts with "trim" or "eval" the error can be a bit
confusing in a function, and this PR make it less confusing.

closes: #16574

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_let.vim
src/testdir/test_lua.vim
src/testdir/test_perl.vim
src/testdir/test_python2.vim
src/testdir/test_python3.vim
src/testdir/test_pyx2.vim
src/testdir/test_pyx3.vim
src/testdir/test_ruby.vim
src/userfunc.c
src/version.c

index 2aba1d3e220242694e36a445d5f4dc49aa116e75..e31b514760afd6bd9dc73579df0aa433eade68fe 100644 (file)
@@ -435,6 +435,24 @@ func Test_let_heredoc_fails()
     call assert_report('Caught exception: ' .. v:exception)
   endtry
 
+  try
+    let v =<< trim trimm
+    trimm
+    call assert_report('No exception thrown')
+  catch /E221:/
+  catch
+    call assert_report('Caught exception: ' .. v:exception)
+  endtry
+
+  try
+    let v =<< trim trim evall
+    evall
+    call assert_report('No exception thrown')
+  catch /E221:/
+  catch
+    call assert_report('Caught exception: ' .. v:exception)
+  endtry
+
   let text =<< trim END
   func WrongSyntax()
     let v =<< that there
index 5225ce8f8ebe7e41531c457fe8125e7a20caf244..043531a5548ba35ccb5d89e1b05ac48bd08e5aad 100644 (file)
@@ -934,7 +934,10 @@ vim.command('let s ..= "B"')
   lua << trim eof
     vim.command('let s ..= "E"')
   eof
-  call assert_equal('ABCDE', s)
+  lua << trimm
+vim.command('let s ..= "F"')
+trimm
+  call assert_equal('ABCDEF', s)
 endfunc
 
 " Test for adding, accessing and removing global variables using the vim.g
index 721179c8e5dbfce38fe26902b1d69297f444daec..31329ca79ed4d65e7babc72fd95d352018bfa965 100644 (file)
@@ -359,7 +359,10 @@ VIM::DoCommand('let s ..= "B"')
   perl << trim eof
     VIM::DoCommand('let s ..= "E"')
   eof
-  call assert_equal('ABCDE', s)
+  perl << trimm
+VIM::DoCommand('let s ..= "F"')
+trimm
+  call assert_equal('ABCDEF', s)
 endfunc
 
 func Test_perl_in_sandbox()
index de5f60794eab7b6bdff5b95ceff9b82615bf9eed..4ba0f8ef985707fb1403809bf2e7299fe215407b 100644 (file)
@@ -263,7 +263,10 @@ s+='B'
   python << trim eof
     s+='E'
   eof
-  call assert_equal('ABCDE', pyxeval('s'))
+python << trimm
+s+='F'
+trimm
+  call assert_equal('ABCDEF', pyxeval('s'))
 endfunc
 
 " Test for the buffer range object
index 20f9dc6c69dca50c74fb3608884053d22353c1d7..c04495433dc4a12de6e91c35f1058724270cdfaf 100644 (file)
@@ -467,7 +467,10 @@ s+='B'
   python3 << trim eof
     s+='E'
   eof
-  call assert_equal('ABCDE', pyxeval('s'))
+  python3 << trimm
+s+='F'
+trimm
+  call assert_equal('ABCDEF', pyxeval('s'))
 endfunc
 
 " Test for the buffer range object
index 781bb417881091fca91289ba3c5a75359287530d..68f1901e28349355e7ba41a257181b62aebcf47a 100644 (file)
@@ -140,7 +140,10 @@ result+='B'
   pyx << trim eof
     result+='E'
   eof
-  call assert_equal('ABCDE', pyxeval('result'))
+  pyx << trimm
+result+='F'
+trimm
+  call assert_equal('ABCDEF', pyxeval('result'))
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index b34fdcbd7e72317dcd7dc45f8dc5c5b4a84ed4be..b02f447e2c63ffa79b56f30f4eea4ed949b88bed 100644 (file)
@@ -139,7 +139,10 @@ result+='B'
   pyx << trim eof
     result+='E'
   eof
-  call assert_equal('ABCDE', pyxeval('result'))
+  pyx << trimm
+result+='F'
+trimm
+  call assert_equal('ABCDEF', pyxeval('result'))
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index cc5f4193f757742299c3158327c8b095d2499d22..d4ff8e0b7283738525c43a84c9e3c17457074df2 100644 (file)
@@ -446,7 +446,10 @@ Vim.command('let s ..= "B"')
   ruby << trim eof
     Vim.command('let s ..= "E"')
   eof
-  call assert_equal('ABCDE', s)
+ruby << trimm
+Vim.command('let s ..= "F"')
+trimm
+  call assert_equal('ABCDEF', s)
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index a60eeb2d76a0d2a19e4a735b7da96e5ecd97e3e8..b7d2752dca27d9f2cb5dc1bcfc5f41cdbc918b86 100644 (file)
@@ -1322,7 +1322,8 @@ get_function_body(
            {
                // ":python <<" continues until a dot, like ":append"
                p = skipwhite(arg + 2);
-               if (STRNCMP(p, "trim", 4) == 0)
+               if (STRNCMP(p, "trim", 4) == 0
+                       && (p[4] == NUL || VIM_ISWHITE(p[4])))
                {
                    // Ignore leading white space.
                    p = skipwhite(p + 4);
@@ -1367,20 +1368,21 @@ get_function_body(
                    current_sctx.sc_version = save_sc_version;
                    if (arg != NULL && STRNCMP(arg, "=<<", 3) == 0)
                    {
+                       int has_trim = FALSE;
+
                        p = skipwhite(arg + 3);
                        while (TRUE)
                        {
-                           if (STRNCMP(p, "trim", 4) == 0)
+                           if (STRNCMP(p, "trim", 4) == 0
+                                   && (p[4] == NUL || VIM_ISWHITE(p[4])))
                            {
                                // Ignore leading white space.
                                p = skipwhite(p + 4);
-                               heredoc_trimmedlen = skipwhite(theline) - theline;
-                               heredoc_trimmed = vim_strnsave(theline, heredoc_trimmedlen);
-                               if (heredoc_trimmed == NULL)
-                                   heredoc_trimmedlen = 0;
+                               has_trim = TRUE;
                                continue;
                            }
-                           if (STRNCMP(p, "eval", 4) == 0)
+                           if (STRNCMP(p, "eval", 4) == 0
+                                   && (p[4] == NUL || VIM_ISWHITE(p[4])))
                            {
                                // Ignore leading white space.
                                p = skipwhite(p + 4);
@@ -1388,6 +1390,13 @@ get_function_body(
                            }
                            break;
                        }
+                       if (has_trim)
+                       {
+                           heredoc_trimmedlen = skipwhite(theline) - theline;
+                           heredoc_trimmed = vim_strnsave(theline, heredoc_trimmedlen);
+                           if (heredoc_trimmed == NULL)
+                               heredoc_trimmedlen = 0;
+                       }
                        skip_until = vim_strnsave(p, skiptowhite(p) - p);
                        getline_options = GETLINE_NONE;
                        is_heredoc = TRUE;
index add59593a91bbe29913dfb7f898b08fa1200a352..545b6354d07642c6804ba820c3e344b6f7fb74dc 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1074,
 /**/
     1073,
 /**/