aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/os/env.c4
-rw-r--r--test/unit/os/env_spec.lua13
2 files changed, 13 insertions, 4 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 082ad58223..879266e3d4 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -1176,7 +1176,9 @@ bool os_setenv_append_path(const char *fname)
temp[0] = NUL;
} else {
xstrlcpy(temp, path, newlen);
- xstrlcat(temp, ENV_SEPSTR, newlen);
+ if (ENV_SEPCHAR != path[pathlen - 1]) {
+ xstrlcat(temp, ENV_SEPSTR, newlen);
+ }
}
xstrlcat(temp, os_buf, newlen);
os_setenv("PATH", temp, 1);
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index ad05b134e0..e7cb5e5d5e 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -78,15 +78,22 @@ describe('env.c', function()
end)
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')
- 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'))
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()
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'))
end)
end)