diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2018-10-10 05:32:21 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-10-10 11:32:21 +0200 |
commit | e17e21e4cfb4c9c402b26e49f36af6c2ca6239ec (patch) | |
tree | 4659d6b9f500bb66ee6c85c6d3f56b0f68e38c6b /src | |
parent | 8c7c8f596268eb46f17143f31a024d4c72192e1b (diff) | |
download | rneovim-e17e21e4cfb4c9c402b26e49f36af6c2ca6239ec.tar.gz rneovim-e17e21e4cfb4c9c402b26e49f36af6c2ca6239ec.tar.bz2 rneovim-e17e21e4cfb4c9c402b26e49f36af6c2ca6239ec.zip |
vim-patch:8.1.0468: MS-Windows: filter command with pipe character fails (#9101)
Problem: MS-Windows: Filter command with pipe character fails. (Johannes
Riecken)
Solution: Find the pipe character outside of quotes. (Yasuhiro Matsumoto,
closes vim/vim#1743, closes vim/vim#3523)
https://github.com/vim/vim/commit/0664089eccec1083dd04ef2255856fb34ce62f15
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_cmds.c | 23 | ||||
-rw-r--r-- | src/nvim/testdir/test_filter_cmd.vim | 13 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a091862e42..4710ae669b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1353,6 +1353,25 @@ do_shell( apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf); } +#if !defined(UNIX) +static char *find_pipe(const char *cmd) +{ + bool inquote = false; + + for (const char *p = cmd; *p != NUL; p++) { + if (!inquote && *p == '|') { + return p; + } + if (*p == '"') { + inquote = !inquote; + } else if (rem_backslash((const char_u *)p)) { + p++; + } + } + return NULL; +} +#endif + /// Create a shell command from a command string, input redirection file and /// output redirection file. /// @@ -1406,7 +1425,7 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) // Don't do this when 'shellquote' is not empty, otherwise the // redirection would be inside the quotes. if (*p_shq == NUL) { - char *const p = strchr(buf, '|'); + char *const p = find_pipe(buf); if (p != NULL) { *p = NUL; } @@ -1414,7 +1433,7 @@ char_u *make_filter_cmd(char_u *cmd, char_u *itmp, char_u *otmp) xstrlcat(buf, " < ", len); xstrlcat(buf, (const char *)itmp, len); if (*p_shq == NUL) { - const char *const p = strchr((const char *)cmd, '|'); + const char *const p = find_pipe((const char *)cmd); if (p != NULL) { xstrlcat(buf, " ", len - 1); // Insert a space before the '|' for DOS xstrlcat(buf, p, len - 1); diff --git a/src/nvim/testdir/test_filter_cmd.vim b/src/nvim/testdir/test_filter_cmd.vim index 5aa5fa64df..86347ab77f 100644 --- a/src/nvim/testdir/test_filter_cmd.vim +++ b/src/nvim/testdir/test_filter_cmd.vim @@ -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 |