]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0811: mksession writes terminal command unquoted v9.2.0811
authorArkissa <mrarkssac@gmail.com>
Sun, 19 Jul 2026 18:30:01 +0000 (18:30 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 19 Jul 2026 18:30:01 +0000 (18:30 +0000)
Problem:  mksession writes terminal command unquoted
          (after v9.2.0732)
Solution: Quote the terminal command (Arkissa)

fixes:  #20788
closes: #20789

Signed-off-by: Arkissa <mrarkssac@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/terminal.c
src/testdir/test_mksession.vim
src/version.c

index 2a2932a8844c6cb0e4fd89ef6a5e7a71b6ae92a9..f136e1efbd4c6a319426d76652114b99b6681349 100644 (file)
@@ -1126,8 +1126,18 @@ term_write_session(FILE *fd, win_T *wp, hashtab_T *terminal_bufs)
     if (fprintf(fd, ".. ' ++type=%s' ", term->tl_job->jv_tty_type) < 0)
        return FAIL;
 # endif
-    if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0)
-       return FAIL;
+    if (term->tl_command != NULL)
+    {
+       char_u *quoted_command = string_quote(term->tl_command, FALSE);
+       if (quoted_command == NULL)
+           return FAIL;
+
+       int ret = fputs(".. ' ' .. ", fd) < 0
+                   || fputs((char *)quoted_command, fd) < 0;
+       vim_free(quoted_command);
+       if (ret)
+           return FAIL;
+    }
     if (put_eol(fd) != OK)
        return FAIL;
 
index 179cbd32422b8cfc5285431559a4f64d5aa26fbc..f7384f601e31cdb83cf881d9ddace03d732a91a1 100644 (file)
@@ -613,6 +613,54 @@ func Test_mksession_terminal_shared_windows()
   call delete('Xtest_mks.out')
 endfunc
 
+func Test_mksession_terminal_shell_command()
+  CheckFeature terminal
+
+  set sessionoptions+=terminal
+  terminal
+  let term_buf = bufnr()
+  eval term_buf->term_setrestore('echo HELLO_WORLD')
+  mksession! Xtest_mks.out
+
+  call StopShellInTerminal(term_buf)
+
+  source Xtest_mks.out
+
+  let restored_buf = bufnr()
+  call assert_equal('terminal', getbufvar(restored_buf, '&buftype'))
+  call WaitForAssert({-> assert_match(
+        \ 'HELLO_WORLD',
+        \ term_getline(restored_buf, 1))})
+  call WaitForAssert({-> assert_match(
+        \ 'finished',
+        \ term_getstatus(restored_buf))})
+
+  bwipe!
+  call delete('Xtest_mks.out')
+endfunc
+
+" Plain :terminal stores no command (tl_command == NULL), so nothing is
+" written after the ':terminal ++curwin ...' line.  Restoring must still
+" produce a running shell terminal.
+func Test_mksession_terminal_default_restore()
+  CheckFeature terminal
+
+  terminal
+  let term_buf = bufnr()
+  mksession! Xtest_mks.out
+  call StopShellInTerminal(term_buf)
+  %bwipe!
+
+  source Xtest_mks.out
+  let restored = bufnr()
+  call assert_equal('terminal', getbufvar(restored, '&buftype'))
+  call WaitForAssert({-> assert_match('running', term_getstatus(restored))})
+  call StopShellInTerminal(restored)
+
+  %bwipe!
+  call delete('Xtest_mks.out')
+endfunc
+
 func Test_mkview_terminal_windows()
   CheckFeature terminal
 
index cf0d47a529254706baa9d936f21b8c0f6d023c65..e523f6dad4cad63de99e38b6ea982717180a70bc 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    811,
 /**/
     810,
 /**/