git.iko.soy/typeable/pandoc
on master help sign in
Shared: readDefaultDataFile: normalize the paths.
6bd686aJohn MacFarlane
src/Text/Pandoc/Shared.hs+7−1
@@ -105,6 +105,7 @@ import Network.HTTP (findHeader, rspBody,
105import Network.Browser (browse, setAllowRedirects, request)
105import Network.Browser (browse, setAllowRedirects, request)
106#ifdef EMBED_DATA_FILES
106#ifdef EMBED_DATA_FILES
107import Text.Pandoc.Data (dataFiles)
107import Text.Pandoc.Data (dataFiles)
108+import System.FilePath ( joinPath )
108#else
109#else
109import Paths_pandoc (getDataFileName)
110import Paths_pandoc (getDataFileName)
110#endif
111#endif
@@ -521,10 +522,15 @@ inDirectory path action = do
521readDefaultDataFile :: FilePath -> IO B.ByteString
522readDefaultDataFile :: FilePath -> IO B.ByteString
522readDefaultDataFile fname =
523readDefaultDataFile fname =
523#ifdef EMBED_DATA_FILES
524#ifdef EMBED_DATA_FILES
524− case lookup fname dataFiles of
525+ case lookup (makeCanonical fname) dataFiles of
525 Nothing -> ioError $ userError
526 Nothing -> ioError $ userError
526 $ "Data file `" ++ fname ++ "' does not exist"
527 $ "Data file `" ++ fname ++ "' does not exist"
527 Just contents -> return contents
528 Just contents -> return contents
529+ where makeCanonical = joinPath . transformPathParts . splitBy (=='/')
530+ transformPathParts = reverse . foldl go []
531+ go as "." = as
532+ go (_:as) ".." = as
533+ go as x = x : as
528#else
534#else
529 getDataFileName ("data" </> fname) >>= B.readFile
535 getDataFileName ("data" </> fname) >>= B.readFile
530#endif
536#endif