mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.0.1012: MS-Windows: problem with $HOME when is was set internally
Problem: MS-Windows: Problem with $HOME when is was set internally.
Solution: Only use the $HOME default internally. (Yasuhiro Matsumoto, closes
vim/vim#2013)
48340b62e8
Restore vim_getenv() behaviour for $HOME on Windows.
This commit is contained in:
parent
b0ab46056f
commit
5ed0975ea2
@ -196,16 +196,19 @@ void init_homedir(void)
|
||||
const char *homedrive = os_getenv("HOMEDRIVE");
|
||||
const char *homepath = os_getenv("HOMEPATH");
|
||||
if (homepath == NULL) {
|
||||
homepath = "\\";
|
||||
homepath = "\\";
|
||||
}
|
||||
if (homedrive != NULL && strlen(homedrive) + strlen(homepath) < MAXPATHL) {
|
||||
if (homedrive != NULL
|
||||
&& strlen(homedrive) + strlen(homepath) < MAXPATHL) {
|
||||
snprintf(os_buf, MAXPATHL, "%s%s", homedrive, homepath);
|
||||
if (os_buf[0] != NUL) {
|
||||
var = os_buf;
|
||||
vim_setenv("HOME", os_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (var == NULL) {
|
||||
var = os_getenv("USERPROFILE");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (var != NULL) {
|
||||
@ -608,6 +611,12 @@ char *vim_getenv(const char *name)
|
||||
return xstrdup(kos_env_path);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (strcmp(name, "HOME") == 0) {
|
||||
return xstrdup(homedir);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool vimruntime = (strcmp(name, "VIMRUNTIME") == 0);
|
||||
if (!vimruntime && strcmp(name, "VIM") != 0) {
|
||||
return NULL;
|
||||
@ -758,7 +767,12 @@ size_t home_replace(const buf_T *const buf, const char_u *src,
|
||||
dirlen = strlen(homedir);
|
||||
}
|
||||
|
||||
const char *const homedir_env = os_getenv("HOME");
|
||||
const char *homedir_env = os_getenv("HOME");
|
||||
#ifdef WIN32
|
||||
if (homedir_env == NULL) {
|
||||
homedir_env = os_getenv("USERPROFILE");
|
||||
}
|
||||
#endif
|
||||
char *homedir_env_mod = (char *)homedir_env;
|
||||
bool must_free = false;
|
||||
|
||||
|
@ -116,6 +116,7 @@ NEW_TESTS ?= \
|
||||
test_visual.res \
|
||||
test_winbuf_close.res \
|
||||
test_window_id.res \
|
||||
test_windows_home.res \
|
||||
test_wordcount.res \
|
||||
test_writefile.res \
|
||||
test_alot_latin.res \
|
||||
|
124
src/nvim/testdir/test_windows_home.vim
Normal file
124
src/nvim/testdir/test_windows_home.vim
Normal file
@ -0,0 +1,124 @@
|
||||
" Test for $HOME on Windows.
|
||||
|
||||
if !has('win32')
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:env = {}
|
||||
|
||||
func s:restore_env()
|
||||
for i in keys(s:env)
|
||||
exe 'let ' . i . '=s:env["' . i . '"]'
|
||||
endfor
|
||||
endfunc
|
||||
|
||||
func s:save_env(...)
|
||||
for i in a:000
|
||||
exe 'let s:env["' . i . '"]=' . i
|
||||
endfor
|
||||
endfunc
|
||||
|
||||
func s:unlet_env(...)
|
||||
for i in a:000
|
||||
exe 'let ' . i . '=""'
|
||||
endfor
|
||||
endfunc
|
||||
|
||||
func CheckHomeIsMissingFromSubprocessEnvironment()
|
||||
silent! let out = system('set')
|
||||
let env = filter(split(out, "\n"), 'v:val=~"^HOME="')
|
||||
call assert_equal(0, len(env))
|
||||
endfunc
|
||||
|
||||
func CheckHomeIsInSubprocessEnvironment(exp)
|
||||
silent! let out = system('set')
|
||||
let env = filter(split(out, "\n"), 'v:val=~"^HOME="')
|
||||
let home = len(env) == 0 ? "" : substitute(env[0], '[^=]\+=', '', '')
|
||||
call assert_equal(a:exp, home)
|
||||
endfunc
|
||||
|
||||
func CheckHome(exp, ...)
|
||||
"call assert_equal(a:exp, $HOME)
|
||||
"call assert_equal(a:exp, expand('~', ':p'))
|
||||
if !a:0
|
||||
call CheckHomeIsMissingFromSubprocessEnvironment()
|
||||
else
|
||||
call CheckHomeIsInSubprocessEnvironment(a:exp)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func TestWindowsHome()
|
||||
command! -nargs=* SaveEnv call <SID>save_env(<f-args>)
|
||||
command! -nargs=* RestoreEnv call <SID>restore_env()
|
||||
command! -nargs=* UnletEnv call <SID>unlet_env(<f-args>)
|
||||
|
||||
SaveEnv $HOME $USERPROFILE $HOMEDRIVE $HOMEPATH
|
||||
try
|
||||
RestoreEnv
|
||||
UnletEnv $HOME $USERPROFILE $HOMEPATH
|
||||
let $HOMEDRIVE = 'C:'
|
||||
call CheckHome('C:\')
|
||||
|
||||
RestoreEnv
|
||||
UnletEnv $HOME $USERPROFILE
|
||||
let $HOMEDRIVE = 'C:'
|
||||
let $HOMEPATH = '\foobar'
|
||||
call CheckHome('C:\foobar')
|
||||
|
||||
RestoreEnv
|
||||
UnletEnv $HOME $HOMEDRIVE $HOMEPATH
|
||||
let $USERPROFILE = 'C:\foo'
|
||||
call CheckHome('C:\foo')
|
||||
|
||||
RestoreEnv
|
||||
UnletEnv $HOME
|
||||
let $USERPROFILE = 'C:\foo'
|
||||
let $HOMEDRIVE = 'C:'
|
||||
let $HOMEPATH = '\baz'
|
||||
call CheckHome('C:\foo')
|
||||
|
||||
RestoreEnv
|
||||
let $HOME = 'C:\bar'
|
||||
let $USERPROFILE = 'C:\foo'
|
||||
let $HOMEDRIVE = 'C:'
|
||||
let $HOMEPATH = '\baz'
|
||||
call CheckHome('C:\bar', 1)
|
||||
|
||||
RestoreEnv
|
||||
let $HOME = '%USERPROFILE%\bar'
|
||||
let $USERPROFILE = 'C:\foo'
|
||||
let $HOMEDRIVE = 'C:'
|
||||
let $HOMEPATH = '\baz'
|
||||
call CheckHome('%USERPROFILE%\bar', 1)
|
||||
|
||||
RestoreEnv
|
||||
let $HOME = '%USERPROFILE'
|
||||
let $USERPROFILE = 'C:\foo'
|
||||
let $HOMEDRIVE = 'C:'
|
||||
let $HOMEPATH = '\baz'
|
||||
call CheckHome('%USERPROFILE', 1)
|
||||
|
||||
RestoreEnv
|
||||
let $HOME = 'C:\%USERPROFILE%'
|
||||
let $USERPROFILE = 'C:\foo'
|
||||
let $HOMEDRIVE = 'C:'
|
||||
let $HOMEPATH = '\baz'
|
||||
call CheckHome('C:\%USERPROFILE%', 1)
|
||||
|
||||
if has('channel')
|
||||
RestoreEnv
|
||||
UnletEnv $HOME
|
||||
let env = ''
|
||||
let job = job_start('cmd /c set', {'out_cb': {ch,x->[env,execute('let env=x')]}})
|
||||
sleep 1
|
||||
let env = filter(split(env, "\n"), 'v:val=="HOME"')
|
||||
let home = len(env) == 0 ? "" : env[0]
|
||||
call assert_equal('', home)
|
||||
endif
|
||||
finally
|
||||
RestoreEnv
|
||||
delcommand SaveEnv
|
||||
delcommand RestoreEnv
|
||||
delcommand UnletEnv
|
||||
endtry
|
||||
endfunc
|
Loading…
Reference in New Issue
Block a user