Skip to content

Commit 6780a8a

Browse files
committed
fix(path): Handle joining of empty strings (fixes #379)
1 parent 77cd1e1 commit 6780a8a

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lua/diffview/path.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ function PathLib:join(...)
317317

318318
for i = 1, table.maxn(segments) do
319319
local cur = segments[i]
320-
if cur then
321-
if i > 1 and not ret:sub(-1, -1):match("[\\/]") then
320+
if cur and cur ~= "" then
321+
if #ret > 0 and not ret:sub(-1, -1):match("[\\/]") then
322322
ret = ret .. self.sep
323323
end
324324
ret = ret .. cur

tests/functional/pathlib_spec.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ describe("diffview.path", function()
266266
eq([[/foo/bar/baz]], pl:join({ "/", "foo", "bar", "baz" }))
267267
eq([[/foo/bar/baz]], pl:join({ "/foo/bar", "baz" }))
268268
eq([[/foo/bar/baz]], pl:join({ "/", "foo/", "/bar///", "/baz" }))
269+
eq([[foo/bar/baz]], pl:join({ "", "foo", "bar", "baz" }))
269270
end)
270271

271272
it("works for Windows paths", function()
@@ -275,6 +276,7 @@ describe("diffview.path", function()
275276
eq([[C:\foo\bar\baz]], pl:join({ "C:\\foo\\bar", "baz" }))
276277
eq([[C:\foo\bar\baz]], pl:join({ "C:\\", "foo\\", "\\bar\\\\", "\\baz" }))
277278
eq([[\foo\bar\baz]], pl:join({ "\\", "foo", "bar", "baz" }))
279+
eq([[foo\bar\baz]], pl:join({ "", "foo", "bar", "baz" }))
278280

279281
eq([[\\foo\bar\baz]], pl:join({ [[\\]], "foo", "bar", "baz" }))
280282
eq([[\\foo\bar\baz]], pl:join({ [[\\foo\\bar]], "baz" }))

0 commit comments

Comments
 (0)