Skip to content

Commit 0664089

Browse files
committed
patch 8.1.0468: MS-Windows: filter command with pipe character fails
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)
1 parent 1d3dbcf commit 0664089

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/ex_cmds.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,26 @@ do_shell(
16761676
apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf);
16771677
}
16781678

1679+
#if !defined(UNIX)
1680+
static char_u *
1681+
find_pipe(char_u *cmd)
1682+
{
1683+
char_u *p;
1684+
int inquote = FALSE;
1685+
1686+
for (p = cmd; *p != NUL; ++p)
1687+
{
1688+
if (!inquote && *p == '|')
1689+
return p;
1690+
if (*p == '"')
1691+
inquote = !inquote;
1692+
else if (rem_backslash(p))
1693+
++p;
1694+
}
1695+
return NULL;
1696+
}
1697+
#endif
1698+
16791699
/*
16801700
* Create a shell command from a command string, input redirection file and
16811701
* output redirection file.
@@ -1746,15 +1766,15 @@ make_filter_cmd(
17461766
*/
17471767
if (*p_shq == NUL)
17481768
{
1749-
p = vim_strchr(buf, '|');
1769+
p = find_pipe(buf);
17501770
if (p != NULL)
17511771
*p = NUL;
17521772
}
17531773
STRCAT(buf, " <"); /* " < " causes problems on Amiga */
17541774
STRCAT(buf, itmp);
17551775
if (*p_shq == NUL)
17561776
{
1757-
p = vim_strchr(cmd, '|');
1777+
p = find_pipe(cmd);
17581778
if (p != NULL)
17591779
{
17601780
STRCAT(buf, " "); /* insert a space before the '|' for DOS */

src/testdir/test_filter_cmd.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,16 @@ func Test_filter_cmd_completion()
7474
call assert_equal('filter /pat/ print', s:complete_filter_cmd('filter /pat/ pri'))
7575
call assert_equal('filter #pat# print', s:complete_filter_cmd('filter #pat# pri'))
7676
endfunc
77+
78+
func Test_filter_cmd_with_filter()
79+
new
80+
set shelltemp
81+
%!echo "a|b"
82+
let out = getline(1)
83+
bw!
84+
if has('win32')
85+
let out = trim(out, '" ')
86+
endif
87+
call assert_equal('a|b', out)
88+
set shelltemp&
89+
endfunction

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static char *(features[]) =
792792

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
468,
795797
/**/
796798
467,
797799
/**/

0 commit comments

Comments
 (0)