]> granicus.if.org Git - vim/commitdiff
patch 8.1.1729: heredoc with trim not properly handled in function v8.1.1729
authorBram Moolenaar <Bram@vim.org>
Sun, 21 Jul 2019 21:04:21 +0000 (23:04 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 21 Jul 2019 21:04:21 +0000 (23:04 +0200)
Problem:    Heredoc with trim not properly handled in function.
Solution:   Allow for missing indent. (FUJIWARA Takuya, closes #4713)

src/testdir/test_let.vim
src/userfunc.c
src/version.c

index 36900821be51cf9e41efbd87ad409380886a9e10..3bb5748947a4114d197c2152621cdbf9d95a01f5 100644 (file)
@@ -188,6 +188,15 @@ func Test_let_heredoc_fails()
   call delete('XheredocBadMarker')
 endfunc
 
+func Test_let_heredoc_trim_no_indent_marker()
+  let text =<< trim END
+  Text
+  with
+  indent
+END
+  call assert_equal(['Text', 'with', 'indent'], text)
+endfunc
+
 " Test for the setting a variable using the heredoc syntax
 func Test_let_heredoc()
   let var1 =<< END
index 0ff1bdb82a34c9997870acb585cb4f2eb1fe1d37..a07b1b3971bae7e05fab29705c5c07918d7cced1 100644 (file)
@@ -2000,8 +2000,6 @@ ex_function(exarg_T *eap)
     int                overwrite = FALSE;
     int                indent;
     int                nesting;
-    char_u     *skip_until = NULL;
-    char_u     *trimmed = NULL;
     dictitem_T *v;
     funcdict_T fudi;
     static int func_nr = 0;        /* number for nameless function */
@@ -2012,6 +2010,9 @@ ex_function(exarg_T *eap)
     int                do_concat = TRUE;
     linenr_T   sourcing_lnum_off;
     linenr_T   sourcing_lnum_top;
+    int                is_heredoc = FALSE;
+    char_u     *skip_until = NULL;
+    char_u     *heredoc_trimmed = NULL;
 
     /*
      * ":function" without argument: list functions.
@@ -2331,17 +2332,28 @@ ex_function(exarg_T *eap)
 
        if (skip_until != NULL)
        {
-           // Between ":append" and "." and between ":python <<EOF" and "EOF"
-           // don't check for ":endfunc".
-           if (trimmed == NULL
-                           || STRNCMP(theline, trimmed, STRLEN(trimmed)) == 0)
+           // Don't check for ":endfunc" between
+           // * ":append" and "."
+           // * ":python <<EOF" and "EOF"
+           // * ":let {var-name} =<< [trim] {marker}" and "{marker}"
+           if (heredoc_trimmed == NULL
+                   || (is_heredoc && skipwhite(theline) == theline)
+                   || STRNCMP(theline, heredoc_trimmed,
+                                                STRLEN(heredoc_trimmed)) == 0)
            {
-               p = trimmed == NULL ? theline : theline + STRLEN(trimmed);
+               if (heredoc_trimmed == NULL)
+                   p = theline;
+               else if (is_heredoc)
+                   p = skipwhite(theline) == theline
+                                ? theline : theline + STRLEN(heredoc_trimmed);
+               else
+                   p = theline + STRLEN(heredoc_trimmed);
                if (STRCMP(p, skip_until) == 0)
                {
                    VIM_CLEAR(skip_until);
-                   VIM_CLEAR(trimmed);
+                   VIM_CLEAR(heredoc_trimmed);
                    do_concat = TRUE;
+                   is_heredoc = FALSE;
                }
            }
        }
@@ -2453,20 +2465,17 @@ ex_function(exarg_T *eap)
                            && (!ASCII_ISALNUM(p[2])
                                || (p[2] == 't' && !ASCII_ISALNUM(p[3]))))))
            {
-               // ":let v =<<" continues until a dot
                p = skipwhite(arg + 3);
                if (STRNCMP(p, "trim", 4) == 0)
                {
                    // Ignore leading white space.
                    p = skipwhite(p + 4);
-                   trimmed = vim_strnsave(theline,
+                   heredoc_trimmed = vim_strnsave(theline,
                                          (int)(skipwhite(theline) - theline));
                }
-               if (*p == NUL)
-                   skip_until = vim_strsave((char_u *)".");
-               else
-                   skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
+               skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
                do_concat = FALSE;
+               is_heredoc = TRUE;
            }
        }
 
index ce47c9b26fe57c23873a53d557d354d0f197cc98..a75f34aa399c2e22cf6068dc02a9dd7a040e01ab 100644 (file)
@@ -777,6 +777,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1729,
 /**/
     1728,
 /**/