Skip to content

fix: only replace path with env var if value defined #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lua/diffview/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ function PathLib:expand(path)

for i = idx, #segments do
local env_var = segments[i]:match("^%$(%S+)$")
if env_var then
segments[i] = uv.os_getenv(env_var) or env_var
if env_var and uv.os_getenv(env_var) ~= nil then
segments[i] = uv.os_getenv(env_var)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/tests/functional/pathlib_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe("diffview.path", function()
local pl = PathLib({ os = "unix" })

eq("/lorem/ipsum/dolor/foo", pl:expand("~/foo"))
eq("foo/EXPANDED_FOO/EXPANDED_BAR/baz", pl:expand("foo/$VAR_FOO/$VAR_BAR/baz"))
eq("foo/EXPANDED_FOO/EXPANDED_BAR/$baz", pl:expand("foo/$VAR_FOO/$VAR_BAR/$baz"))
end)
end)

Expand Down