1
0
forked from aniani/vim

patch 8.2.1979: "term_opencmd" option of term_start() is truncated

Problem:    "term_opencmd" option of term_start() is truncated. (Sergey
            Vlasov)
Solution:   Allocate the buffer to hold the command. (closes #7284)
This commit is contained in:
Bram Moolenaar
2020-11-12 15:12:15 +01:00
parent 957cf67d50
commit 47c5ea44b9
3 changed files with 17 additions and 9 deletions

View File

@@ -3450,15 +3450,19 @@ term_after_channel_closed(term_T *term)
if (term->tl_finish == TL_FINISH_OPEN if (term->tl_finish == TL_FINISH_OPEN
&& term->tl_buffer->b_nwindows == 0) && term->tl_buffer->b_nwindows == 0)
{ {
char buf[50]; char *cmd = term->tl_opencmd == NULL
? "botright sbuf %d"
: (char *)term->tl_opencmd;
size_t len = strlen(cmd) + 50;
char *buf = alloc(len);
// TODO: use term_opencmd if (buf != NULL)
ch_log(NULL, "terminal job finished, opening window"); {
vim_snprintf(buf, sizeof(buf), ch_log(NULL, "terminal job finished, opening window");
term->tl_opencmd == NULL vim_snprintf(buf, len, cmd, fnum);
? "botright sbuf %d" do_cmdline_cmd((char_u *)buf);
: (char *)term->tl_opencmd, fnum); vim_free(buf);
do_cmdline_cmd((char_u *)buf); }
} }
else else
ch_log(NULL, "terminal job finished"); ch_log(NULL, "terminal job finished");

View File

@@ -567,10 +567,12 @@ func Test_terminal_finish_open_close()
call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:') call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:')
call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:') call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:')
call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'}) call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d | let g:result = "opened the buffer in a window"'})
close! close!
call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime)
call assert_equal(4, winheight(0)) call assert_equal(4, winheight(0))
call assert_equal('opened the buffer in a window', g:result)
unlet g:result
bwipe bwipe
endfunc endfunc

View File

@@ -750,6 +750,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 */
/**/
1979,
/**/ /**/
1978, 1978,
/**/ /**/