forked from aniani/vim
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.
This commit is contained in:
@@ -4074,7 +4074,7 @@ wait4pid(pid_t child, waitstatus *status)
|
|||||||
mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
|
mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char_u *p;
|
char_u *p, *d;
|
||||||
int inquote;
|
int inquote;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -4092,26 +4092,34 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
|
|||||||
if (i == 1)
|
if (i == 1)
|
||||||
(*argv)[*argc] = (char *)p;
|
(*argv)[*argc] = (char *)p;
|
||||||
++*argc;
|
++*argc;
|
||||||
|
d = p;
|
||||||
while (*p != NUL && (inquote || (*p != ' ' && *p != TAB)))
|
while (*p != NUL && (inquote || (*p != ' ' && *p != TAB)))
|
||||||
{
|
{
|
||||||
if (p[0] == '"')
|
if (p[0] == '"')
|
||||||
|
/* quotes surrounding an argument and are dropped */
|
||||||
inquote = !inquote;
|
inquote = !inquote;
|
||||||
else if (p[0] == '\\' && p[1] != NUL)
|
else
|
||||||
|
{
|
||||||
|
if (p[0] == '\\' && p[1] != NUL)
|
||||||
{
|
{
|
||||||
/* First pass: skip over "\ " and "\"".
|
/* First pass: skip over "\ " and "\"".
|
||||||
* Second pass: Remove the backslash. */
|
* Second pass: Remove the backslash. */
|
||||||
if (i == 1)
|
|
||||||
mch_memmove(p, p + 1, STRLEN(p));
|
|
||||||
else
|
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
|
if (i == 1)
|
||||||
|
*d++ = *p;
|
||||||
|
}
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
if (*p == NUL)
|
if (*p == NUL)
|
||||||
break;
|
{
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
*p++ = NUL;
|
*d++ = NUL;
|
||||||
p = skipwhite(p);
|
break;
|
||||||
|
}
|
||||||
|
if (i == 1)
|
||||||
|
*d++ = NUL;
|
||||||
|
p = skipwhite(p + 1);
|
||||||
}
|
}
|
||||||
if (*argv == NULL)
|
if (*argv == NULL)
|
||||||
{
|
{
|
||||||
|
@@ -1590,6 +1590,22 @@ func Test_collapse_buffers()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
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()
|
func Test_raw_passes_nul()
|
||||||
if !executable('cat') || !has('job')
|
if !executable('cat') || !has('job')
|
||||||
return
|
return
|
||||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1176,
|
||||||
/**/
|
/**/
|
||||||
1175,
|
1175,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user