Skip to content

Commit 46ee11a

Browse files
committed
Fix Path:find_upwards()
The prior implementation had several implementation issues which caused an infinite loop if the search turned up empty. This new implementation corrects the bounds check to stop searching once we've searched everywhere we can, and properly searches the root directory
1 parent 102c029 commit 46ee11a

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

lua/plenary/path.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,11 @@ function Path:_st_mode()
296296
end
297297

298298
function Path:joinpath(...)
299-
return Path:new(self.filename, ...)
299+
if string.char(self.filename:byte(-1)) == path.sep then
300+
return Path:new(self.filename:sub(0, -2), ...)
301+
else
302+
return Path:new(self.filename, ...)
303+
end
300304
end
301305

302306
function Path:absolute()
@@ -917,14 +921,20 @@ end
917921

918922
function Path:find_upwards(filename)
919923
local folder = Path:new(self)
920-
while self:absolute() ~= path.root do
924+
local root = path.root(folder:absolute())
925+
926+
while true do
921927
local p = folder:joinpath(filename)
922928
if p:exists() then
923929
return p
924930
end
931+
if folder:absolute() == root then
932+
break
933+
end
925934
folder = folder:parent()
926935
end
927-
return ""
936+
937+
return nil
928938
end
929939

930940
return Path

0 commit comments

Comments
 (0)