mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(termopen): avoid ambiguity in URI when CWD is root dir (#16988)
This commit is contained in:
parent
6f0baa0bb7
commit
18fbdaeeab
@ -10790,10 +10790,16 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
// "/home/foo/…" => "~/…"
|
||||
size_t len = home_replace(NULL, NameBuff, IObuff, sizeof(IObuff), true);
|
||||
// Trim slash.
|
||||
if (IObuff[len - 1] == '\\' || IObuff[len - 1] == '/') {
|
||||
if (len != 1 && (IObuff[len - 1] == '\\' || IObuff[len - 1] == '/')) {
|
||||
IObuff[len - 1] = '\0';
|
||||
}
|
||||
|
||||
if (len == 1 && IObuff[0] == '/') {
|
||||
// Avoid ambiguity in the URI when CWD is root directory.
|
||||
IObuff[1] = '.';
|
||||
IObuff[2] = '\0';
|
||||
}
|
||||
|
||||
// Terminal URI: "term://$CWD//$PID:$CMD"
|
||||
snprintf((char *)NameBuff, sizeof(NameBuff), "term://%s//%d:%s",
|
||||
(char *)IObuff, pid, cmd);
|
||||
|
@ -1,5 +1,6 @@
|
||||
local lfs = require('lfs')
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
@ -119,4 +120,45 @@ describe(':mksession', function()
|
||||
command('bd!')
|
||||
sleep(100) -- Make sure the process exits.
|
||||
end)
|
||||
|
||||
it('restores CWD for :terminal buffer at root directory #16988', function()
|
||||
if helpers.iswin() then
|
||||
pending('N/A for Windows')
|
||||
return
|
||||
end
|
||||
|
||||
local screen
|
||||
local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
|
||||
local session_path = cwd_dir..'/'..session_file
|
||||
|
||||
screen = Screen.new(50, 6)
|
||||
screen:attach({rgb=false})
|
||||
local expected_screen = [[
|
||||
^/ |
|
||||
|
|
||||
[Process exited 0] |
|
||||
|
|
||||
|
|
||||
|
|
||||
]]
|
||||
|
||||
command('cd /')
|
||||
command('terminal echo $PWD')
|
||||
|
||||
-- Verify that the terminal's working directory is "/".
|
||||
screen:expect(expected_screen)
|
||||
|
||||
command('cd '..cwd_dir)
|
||||
command('mksession '..session_path)
|
||||
command('qall!')
|
||||
|
||||
-- Create a new test instance of Nvim.
|
||||
clear()
|
||||
screen = Screen.new(50, 6)
|
||||
screen:attach({rgb=false})
|
||||
command('silent source '..session_path)
|
||||
|
||||
-- Verify that the terminal's working directory is "/".
|
||||
screen:expect(expected_screen)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user