mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-27 09:55:57 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
46e7475158
commit
1c841b85e8
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user