Skip to content

Commit 9d654a8

Browse files
committed
patch 8.0.1051: cannot run terminal with spaces in argument
Problem: Cannot run terminal with spaces in argument. Solution: Accept backslash to escape space and other characters. (closes #1999)
1 parent 595a402 commit 9d654a8

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/os_unix.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4094,8 +4094,17 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
40944094
++*argc;
40954095
while (*p != NUL && (inquote || (*p != ' ' && *p != TAB)))
40964096
{
4097-
if (*p == '"')
4097+
if (p[0] == '"')
40984098
inquote = !inquote;
4099+
else if (p[0] == '\\' && p[1] != NUL)
4100+
{
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
4106+
++p;
4107+
}
40994108
++p;
41004109
}
41014110
if (*p == NUL)

src/testdir/test_terminal.vim

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ func Test_terminal_size()
293293
let size = term_getsize('')
294294
bwipe!
295295
call assert_equal([7, 27], size)
296+
297+
call delete('Xtext')
296298
endfunc
297299

298300
func Test_terminal_curwin()
@@ -325,7 +327,7 @@ func Test_terminal_curwin()
325327

326328
split dummy
327329
bwipe!
328-
330+
call delete('Xtext')
329331
endfunc
330332

331333
func Test_finish_open_close()
@@ -555,3 +557,19 @@ func Test_terminal_no_cmd()
555557
call assert_equal('look here', term_getline(buf, 1))
556558
bwipe!
557559
endfunc
560+
561+
func Test_terminal_special_chars()
562+
" this file name only works on Unix
563+
if !has('unix')
564+
return
565+
endif
566+
call mkdir('Xdir with spaces')
567+
call writefile(['x'], 'Xdir with spaces/quoted"file')
568+
term ls Xdir\ with\ spaces/quoted\"file
569+
call WaitFor('term_getline("", 1) =~ "quoted"')
570+
call assert_match('quoted"file', term_getline('', 1))
571+
call term_wait('')
572+
573+
call delete('Xdir with spaces', 'rf')
574+
bwipe
575+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1051,
772774
/**/
773775
1050,
774776
/**/

0 commit comments

Comments
 (0)