]> granicus.if.org Git - vim/commitdiff
patch 8.2.0453: trailing space in job_start() command causes empty argument v8.2.0453
authorBram Moolenaar <Bram@vim.org>
Thu, 26 Mar 2020 15:27:38 +0000 (16:27 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 26 Mar 2020 15:27:38 +0000 (16:27 +0100)
Problem:    Trailing space in job_start() command causes empty argument.
Solution:   Ignore trailing space. (closes #5851)

src/misc2.c
src/testdir/test_channel.vim
src/version.c

index 6ef420cabfbaf7c243a29192d1d6331ab2bc4004..864d1fd40b3a2817f348515c03bf94248dab338e 100644 (file)
@@ -4242,14 +4242,14 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
      * 1: find number of arguments
      * 2: separate them and build argv[]
      */
-    for (i = 0; i < 2; ++i)
+    for (i = 1; i <= 2; ++i)
     {
        p = skipwhite(cmd);
        inquote = FALSE;
        *argc = 0;
-       for (;;)
+       while (*p != NUL)
        {
-           if (i == 1)
+           if (i == 2)
                (*argv)[*argc] = (char *)p;
            ++*argc;
            d = p;
@@ -4266,18 +4266,18 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
                        // Second pass: Remove the backslash.
                        ++p;
                    }
-                   if (i == 1)
+                   if (i == 2)
                        *d++ = *p;
                }
                ++p;
            }
            if (*p == NUL)
            {
-               if (i == 1)
+               if (i == 2)
                    *d++ = NUL;
                break;
            }
-           if (i == 1)
+           if (i == 2)
                *d++ = NUL;
            p = skipwhite(p + 1);
        }
index 8fa67ef6571b1df186563b8ef20743faaeafd897..fc8b3729ab3db0e63cc1bc7e625069fff00f320d 100644 (file)
@@ -2035,4 +2035,12 @@ func Test_issue_5485()
   unlet $VAR1
 endfunc
 
+func Test_job_trailing_space_unix()
+  CheckUnix
+  CheckExecutable cat
+  let job = job_start("cat ", #{in_io: 'null'})
+  call WaitForAssert({-> assert_equal("dead", job_status(job))})
+  call assert_equal(0, job_info(job).exitval)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 94fcb6096a94effaf95e32fa60f59d2cb717a407..a2a2986ef9c71d5ad8c55460fd06eb5b39854473 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    453,
 /**/
     452,
 /**/