Skip to content

Commit ca13fb5

Browse files
committed
normalize ignore bad make_relative
1 parent 4c7081f commit ca13fb5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lua/plenary/path2.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,9 @@ function Path:normalize(relative_to, walk_up)
861861
if relative_to == nil then
862862
p = self
863863
else
864-
p = self:_make_relative(relative_to, walk_up)
864+
local ok
865+
ok, p = pcall(Path._make_relative, self, relative_to, walk_up)
866+
p = ok and assert(p) or self
865867
end
866868

867869
local relparts = resolve_dots(p.relparts)

tests/plenary/path2_spec.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ describe("Path2", function()
435435
local expect = Path:new { "C:", "a", "b" }
436436
assert.are.same(expect.filename, p:normalize())
437437
end)
438+
439+
it_cross_plat("ignores bad make_relative", function()
440+
local p = Path:new "foobar"
441+
assert.are.same(p.filename, p:normalize(path.home))
442+
end)
438443
end)
439444

440445
describe(":shorten", function()

0 commit comments

Comments
 (0)