]> granicus.if.org Git - vim/commitdiff
patch 8.1.0468: MS-Windows: filter command with pipe character fails v8.1.0468
authorBram Moolenaar <Bram@vim.org>
Tue, 9 Oct 2018 19:49:33 +0000 (21:49 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 9 Oct 2018 19:49:33 +0000 (21:49 +0200)
Problem:    MS-Windows: Filter command with pipe character fails. (Johannes
            Riecken)
Solution:   Find the pipe character outside of quotes. (Yasuhiro Matsumoto,
            closes #1743, closes #3523)

src/ex_cmds.c
src/testdir/test_filter_cmd.vim
src/version.c

index 99c19f9136755a997c79a24c2aa9bca04dd21b34..0a5387c52b30eabbf6d9e9a45e1ad817f83cd6e1 100644 (file)
@@ -1676,6 +1676,26 @@ do_shell(
     apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf);
 }
 
+#if !defined(UNIX)
+    static char_u *
+find_pipe(char_u *cmd)
+{
+    char_u  *p;
+    int            inquote = FALSE;
+
+    for (p = cmd; *p != NUL; ++p)
+    {
+       if (!inquote && *p == '|')
+           return p;
+       if (*p == '"')
+           inquote = !inquote;
+       else if (rem_backslash(p))
+           ++p;
+    }
+    return NULL;
+}
+#endif
+
 /*
  * Create a shell command from a command string, input redirection file and
  * output redirection file.
@@ -1746,7 +1766,7 @@ make_filter_cmd(
         */
        if (*p_shq == NUL)
        {
-           p = vim_strchr(buf, '|');
+           p = find_pipe(buf);
            if (p != NULL)
                *p = NUL;
        }
@@ -1754,7 +1774,7 @@ make_filter_cmd(
        STRCAT(buf, itmp);
        if (*p_shq == NUL)
        {
-           p = vim_strchr(cmd, '|');
+           p = find_pipe(cmd);
            if (p != NULL)
            {
                STRCAT(buf, " ");   /* insert a space before the '|' for DOS */
index 5aa5fa64dfd97c69302b481d05520b822bd82068..86347ab77f0753be2a043227868c4ffb36514622 100644 (file)
@@ -74,3 +74,16 @@ func Test_filter_cmd_completion()
   call assert_equal('filter /pat/ print', s:complete_filter_cmd('filter /pat/ pri'))
   call assert_equal('filter #pat# print', s:complete_filter_cmd('filter #pat# pri'))
 endfunc
+
+func Test_filter_cmd_with_filter()
+  new
+  set shelltemp
+  %!echo "a|b"
+  let out = getline(1)
+  bw!
+  if has('win32')
+    let out = trim(out, '" ')
+  endif
+  call assert_equal('a|b', out)
+  set shelltemp&
+endfunction
index def449a5763d1c66937e61096b0c72322f0a5d41..d4cccb941ab98057dc8fd2c8761aec27eadaae58 100644 (file)
@@ -792,6 +792,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    468,
 /**/
     467,
 /**/