mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
{
int i;
- char_u *p;
+ char_u *p, *d;
int inquote;
/*
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)
{
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