Skip to content

Commit

Permalink
vim-patch:8.1.0468: MS-Windows: filter command with pipe character fa…
Browse files Browse the repository at this point in the history
…ils (#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)
vim/vim@0664089
  • Loading branch information
janlazo authored and justinmk committed Oct 10, 2018
1 parent 8c7c8f5 commit e17e21e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/nvim/ex_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -1406,15 +1425,15 @@ 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;
}
}
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);
Expand Down
13 changes: 13 additions & 0 deletions src/nvim/testdir/test_filter_cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e17e21e

Please sign in to comment.