Skip to content

Commit d78f03f

Browse files
committed
patch 8.0.1176: job_start() does not handle quote and backslash correctly
Problem: Job_start() does not handle quote and backslash correctly. Solution: Remove quotes, recognize and remove backslashes.
1 parent c902609 commit d78f03f

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/os_unix.c

+17-9
Original file line numberDiff line numberDiff line change
@@ -4074,7 +4074,7 @@ wait4pid(pid_t child, waitstatus *status)
40744074
mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
40754075
{
40764076
int i;
4077-
char_u *p;
4077+
char_u *p, *d;
40784078
int inquote;
40794079

40804080
/*
@@ -4092,26 +4092,34 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
40924092
if (i == 1)
40934093
(*argv)[*argc] = (char *)p;
40944094
++*argc;
4095+
d = p;
40954096
while (*p != NUL && (inquote || (*p != ' ' && *p != TAB)))
40964097
{
40974098
if (p[0] == '"')
4099+
/* quotes surrounding an argument and are dropped */
40984100
inquote = !inquote;
4099-
else if (p[0] == '\\' && p[1] != NUL)
4101+
else
41004102
{
4101-
/* First pass: skip over "\ " and "\"".
4102-
* Second pass: Remove the backslash. */
4103-
if (i == 1)
4104-
mch_memmove(p, p + 1, STRLEN(p));
4105-
else
4103+
if (p[0] == '\\' && p[1] != NUL)
4104+
{
4105+
/* First pass: skip over "\ " and "\"".
4106+
* Second pass: Remove the backslash. */
41064107
++p;
4108+
}
4109+
if (i == 1)
4110+
*d++ = *p;
41074111
}
41084112
++p;
41094113
}
41104114
if (*p == NUL)
4115+
{
4116+
if (i == 1)
4117+
*d++ = NUL;
41114118
break;
4119+
}
41124120
if (i == 1)
4113-
*p++ = NUL;
4114-
p = skipwhite(p);
4121+
*d++ = NUL;
4122+
p = skipwhite(p + 1);
41154123
}
41164124
if (*argv == NULL)
41174125
{

src/testdir/test_channel.vim

+16
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,22 @@ func Test_collapse_buffers()
15901590
bwipe!
15911591
endfunc
15921592

1593+
func Test_cmd_parsing()
1594+
if !has('unix')
1595+
return
1596+
endif
1597+
call assert_false(filereadable("file with space"))
1598+
let job = job_start('touch "file with space"')
1599+
call WaitFor('filereadable("file with space")')
1600+
call assert_true(filereadable("file with space"))
1601+
call delete("file with space")
1602+
1603+
let job = job_start('touch file\ with\ space')
1604+
call WaitFor('filereadable("file with space")')
1605+
call assert_true(filereadable("file with space"))
1606+
call delete("file with space")
1607+
endfunc
1608+
15931609
func Test_raw_passes_nul()
15941610
if !executable('cat') || !has('job')
15951611
return

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1176,
764766
/**/
765767
1175,
766768
/**/

0 commit comments

Comments
 (0)