From e1f8c4b396354f8bf29c3b9f04e9b3f980c70d31 Mon Sep 17 00:00:00 2001 From: Even Brenden <evenbrenden@gmail.com> Date: Thu, 27 Jan 2022 23:56:07 +0100 Subject: [PATCH] Handle consecutive ".."s in makeCanonical As an example, prior to this commit, "../../file" would evaluate to "file", when it should be unchanged. --- src/Text/Pandoc/Class/PandocMonad.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Text/Pandoc/Class/PandocMonad.hs b/src/Text/Pandoc/Class/PandocMonad.hs index 144a13ba4..05cc156d0 100644 --- a/src/Text/Pandoc/Class/PandocMonad.hs +++ b/src/Text/Pandoc/Class/PandocMonad.hs @@ -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