From 1c841b85e8b3664957cd6e89fb35e2d74ba2964f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 9 Sep 2026 18:36:36 +0000 Subject: [PATCH] Text.Pandoc.Class.PandocMonad: fix isRelativeToParentDir. The check used a string prefix comparison, so any path beginning with two dots (e.g. `..foo/bar.yaml`) was treated as pointing outside the working directory, wrongly disabling the user data directory fallback in checkUserDataDir. Compare the first path component instead. Co-Authored-By: Claude --- 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 bf214f9e0..ba8b8439f 100644 --- a/src/Text/Pandoc/Class/PandocMonad.hs +++ b/src/Text/Pandoc/Class/PandocMonad.hs @@ -72,7 +72,7 @@ import Network.URI ( escapeURIString, nonStrictRelativeTo, unEscapeString, parseURIReference, isAllowedInURI, parseURI, URI(..) ) import System.FilePath ((), takeExtension, dropExtension, - isRelative, makeRelative) + isRelative, makeRelative, splitDirectories) import System.Random (StdGen) import Text.Collate.Lang (Lang(..), parseLang) import Text.Pandoc.Class.CommonState (CommonState (..)) @@ -432,8 +432,9 @@ extractURIData upath = -- | Checks if the file path is relative to a parent directory. isRelativeToParentDir :: FilePath -> Bool isRelativeToParentDir fname = - let canonical = makeCanonical fname - in length canonical >= 2 && take 2 canonical == ".." + case splitDirectories (makeCanonical fname) of + "..":_ -> True + _ -> False -- | Returns possible user data directory if the file path refers to a file or -- subdirectory within it.