fix(windows):exepath, stdpath return wrong slashes #19111

exepath and stdpath should respect shellslash and return path with
proper file separator.
Closes #13787
This commit is contained in:
Enan Ajmain
2022-07-18 06:00:08 +06:00
committed by Justin M. Keyes
parent 49a9fb2d98
commit d9521c71d1
4 changed files with 32 additions and 4 deletions

View File

@ -2056,6 +2056,12 @@ static void f_exepath(typval_T *argvars, typval_T *rettv, FunPtr fptr)
(void)os_can_exe(tv_get_string(&argvars[0]), &path, true);
#ifdef BACKSLASH_IN_FILENAME
if (path != NULL) {
slash_adjust((char_u *)path);
}
#endif
rettv->v_type = VAR_STRING;
rettv->vval.v_string = (char_u *)path;
}

View File

@ -104,6 +104,10 @@ char *get_xdg_home(const XDGVarType idx)
#else
dir = concat_fnames_realloc(dir, "nvim", true);
#endif
#ifdef BACKSLASH_IN_FILENAME
slash_adjust((char_u *)dir);
#endif
}
return dir;
}

View File

@ -23,6 +23,7 @@ local iswin = helpers.iswin
local startswith = helpers.startswith
local write_file = helpers.write_file
local meths = helpers.meths
local alter_slashes = helpers.alter_slashes
describe('startup', function()
before_each(function()
@ -521,10 +522,12 @@ describe('sysinit', function()
end)
describe('clean', function()
clear()
ok(string.find(meths.get_option('runtimepath'), funcs.stdpath('config'), 1, true) ~= nil)
clear('--clean')
ok(string.find(meths.get_option('runtimepath'), funcs.stdpath('config'), 1, true) == nil)
it('--clean', function()
clear()
ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) ~= nil)
clear('--clean')
ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) == nil)
end)
end)
describe('user config init', function()

View File

@ -17,6 +17,21 @@ describe('executable()', function()
eq(1, call('executable', 'false'))
end)
if iswin() then
it('exepath respects shellslash', function()
command('let $PATH = fnamemodify("./test/functional/fixtures/bin", ":p")')
eq([[test\functional\fixtures\bin\null.CMD]], call('fnamemodify', call('exepath', 'null'), ':.'))
command('set shellslash')
eq('test/functional/fixtures/bin/null.CMD', call('fnamemodify', call('exepath', 'null'), ':.'))
end)
it('stdpath respects shellslash', function()
eq([[build\Xtest_xdg\share\nvim-data]], call('fnamemodify', call('stdpath', 'data'), ':.'))
command('set shellslash')
eq('build/Xtest_xdg/share/nvim-data', call('fnamemodify', call('stdpath', 'data'), ':.'))
end)
end
it('fails for invalid values', function()
for _, input in ipairs({'v:null', 'v:true', 'v:false', '{}', '[]'}) do
eq('Vim(call):E928: String required', exc_exec('call executable('..input..')'))