summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-10-06 01:07:41 +0200
committerBram Moolenaar <Bram@vim.org>2017-10-06 01:07:41 +0200
commitd78f03f86045184dfd191f00359baa61e2e79d1f (patch)
tree3652e1c4a1072058b0d51d480b4cdfa3e6d5abc0
parentc902609f69b5662484f78dbf509715940d4134e4 (diff)
downloadvim-git-d78f03f86045184dfd191f00359baa61e2e79d1f.tar.gz
patch 8.0.1176: job_start() does not handle quote and backslash correctlyv8.0.1176
Problem: Job_start() does not handle quote and backslash correctly. Solution: Remove quotes, recognize and remove backslashes.
-rw-r--r--src/os_unix.c26
-rw-r--r--src/testdir/test_channel.vim16
-rw-r--r--src/version.c2
3 files changed, 35 insertions, 9 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 2a8e6ee43..59e5745de 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4074,7 +4074,7 @@ wait4pid(pid_t child, waitstatus *status)
mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
{
int i;
- char_u *p;
+ char_u *p, *d;
int inquote;
/*
@@ -4092,26 +4092,34 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
if (i == 1)
(*argv)[*argc] = (char *)p;
++*argc;
+ d = p;
while (*p != NUL && (inquote || (*p != ' ' && *p != TAB)))
{
if (p[0] == '"')
+ /* quotes surrounding an argument and are dropped */
inquote = !inquote;
- else if (p[0] == '\\' && p[1] != NUL)
+ else
{
- /* First pass: skip over "\ " and "\"".
- * Second pass: Remove the backslash. */
- if (i == 1)
- mch_memmove(p, p + 1, STRLEN(p));
- else
+ if (p[0] == '\\' && p[1] != NUL)
+ {
+ /* First pass: skip over "\ " and "\"".
+ * Second pass: Remove the backslash. */
++p;
+ }
+ if (i == 1)
+ *d++ = *p;
}
++p;
}
if (*p == NUL)
+ {
+ if (i == 1)
+ *d++ = NUL;
break;
+ }
if (i == 1)
- *p++ = NUL;
- p = skipwhite(p);
+ *d++ = NUL;
+ p = skipwhite(p + 1);
}
if (*argv == NULL)
{
diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 951f9a3ba..9dba0c4b7 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -1590,6 +1590,22 @@ func Test_collapse_buffers()
bwipe!
endfunc
+func Test_cmd_parsing()
+ if !has('unix')
+ return
+ endif
+ call assert_false(filereadable("file with space"))
+ let job = job_start('touch "file with space"')
+ call WaitFor('filereadable("file with space")')
+ call assert_true(filereadable("file with space"))
+ call delete("file with space")
+
+ let job = job_start('touch file\ with\ space')
+ call WaitFor('filereadable("file with space")')
+ call assert_true(filereadable("file with space"))
+ call delete("file with space")
+endfunc
+
func Test_raw_passes_nul()
if !executable('cat') || !has('job')
return
diff --git a/src/version.c b/src/version.c
index b31943fc0..8d7a5e5bd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1176,
+/**/
1175,
/**/
1174,