mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 17:36:29 +00:00
win: avoid duplicate separators in $PATH #12869
Seems like redundant env var separators (";" on Windows) in $PATH can
cause weird behavior. From #7377:
> After some time, system(['win32yank', '-o']) and system('win32yank -o')
> start returning different results: specifically first returns an
> empty string.
>
> 1. $PATH weirdly contains double semicolon followed by path to the
> “installation directory” (unpacked directory from archive).
> 2. If I run `let $PATH=substitute($PATH, ';;', ';', 'g')` the problem is fixed.
close #7377
ref 224f99b85d
This commit is contained in:
@@ -1176,8 +1176,10 @@ bool os_setenv_append_path(const char *fname)
|
|||||||
temp[0] = NUL;
|
temp[0] = NUL;
|
||||||
} else {
|
} else {
|
||||||
xstrlcpy(temp, path, newlen);
|
xstrlcpy(temp, path, newlen);
|
||||||
|
if (ENV_SEPCHAR != path[pathlen - 1]) {
|
||||||
xstrlcat(temp, ENV_SEPSTR, newlen);
|
xstrlcat(temp, ENV_SEPSTR, newlen);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
xstrlcat(temp, os_buf, newlen);
|
xstrlcat(temp, os_buf, newlen);
|
||||||
os_setenv("PATH", temp, 1);
|
os_setenv("PATH", temp, 1);
|
||||||
xfree(temp);
|
xfree(temp);
|
||||||
|
@@ -78,15 +78,22 @@ describe('env.c', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe('os_setenv_append_path', function()
|
describe('os_setenv_append_path', function()
|
||||||
itp('appends /foo/bar to $PATH', function()
|
itp('appends :/foo/bar to $PATH', function()
|
||||||
local original_path = os.getenv('PATH')
|
local original_path = os.getenv('PATH')
|
||||||
eq(true, cimp.os_setenv_append_path(to_cstr('/foo/bar/baz')))
|
eq(true, cimp.os_setenv_append_path(to_cstr('/foo/bar/baz.exe')))
|
||||||
eq(original_path..':/foo/bar', os.getenv('PATH'))
|
eq(original_path..':/foo/bar', os.getenv('PATH'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
itp('avoids redundant separator when appending to $PATH #7377', function()
|
||||||
|
os_setenv('PATH', '/a/b/c:', true)
|
||||||
|
eq(true, cimp.os_setenv_append_path(to_cstr('/foo/bar/baz.exe')))
|
||||||
|
-- Must not have duplicate separators. #7377
|
||||||
|
eq('/a/b/c:/foo/bar', os.getenv('PATH'))
|
||||||
|
end)
|
||||||
|
|
||||||
itp('returns false if `fname` is not absolute', function()
|
itp('returns false if `fname` is not absolute', function()
|
||||||
local original_path = os.getenv('PATH')
|
local original_path = os.getenv('PATH')
|
||||||
eq(false, cimp.os_setenv_append_path(to_cstr('foo/bar/baz')))
|
eq(false, cimp.os_setenv_append_path(to_cstr('foo/bar/baz.exe')))
|
||||||
eq(original_path, os.getenv('PATH'))
|
eq(original_path, os.getenv('PATH'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user