From ed806317d9caacd81c5ee482cfa8c31705dcd8ec Mon Sep 17 00:00:00 2001 From: bryankenote Date: Wed, 19 Feb 2025 14:13:59 -0800 Subject: [PATCH 1/2] fix: only replace path with env var if value defined, otherwise leave $ character in the path --- lua/diffview/path.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/diffview/path.lua b/lua/diffview/path.lua index 3fc4b20f..101e123c 100644 --- a/lua/diffview/path.lua +++ b/lua/diffview/path.lua @@ -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 From 90a72f0c362c55269b5686029d81ad569d66b87c Mon Sep 17 00:00:00 2001 From: bryankenote Date: Thu, 20 Feb 2025 14:00:31 -0800 Subject: [PATCH 2/2] add `$` to test case on a segment with no corresponding env var --- lua/diffview/tests/functional/pathlib_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/diffview/tests/functional/pathlib_spec.lua b/lua/diffview/tests/functional/pathlib_spec.lua index 4ace9661..7c451578 100644 --- a/lua/diffview/tests/functional/pathlib_spec.lua +++ b/lua/diffview/tests/functional/pathlib_spec.lua @@ -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)