Handle consecutive ".."s in makeCanonical

As an example, prior to this commit, "../../file" would evaluate to
"file", when it should be unchanged.
This commit is contained in:
Even Brenden 2022-01-27 23:56:07 +01:00 committed by John MacFarlane
parent 7fbce82f2f
commit e1f8c4b396

View file

@ -637,9 +637,10 @@ checkExistence fn = do
makeCanonical :: FilePath -> FilePath
makeCanonical = Posix.joinPath . transformPathParts . splitDirectories
where transformPathParts = reverse . foldl' go []
go as "." = as
go (_:as) ".." = as
go as x = x : as
go as "." = as
go ("..":as) ".." = ["..", ".."] <> as
go (_:as) ".." = as
go as x = x : as
-- | Tries to run an action on a file: for each directory given, a
-- filepath is created from the given filename, and the action is run on