git.iko.soy/typeable/pandoc
on master help sign in
Shared: readDefaultDataFile: normalize the paths.

This fixes bugs in `--self-contained` on pandoc compiled with `embed_data_files`. The bugs affect (a) paths containing `..`, (b) Windows, where `\` is path separator. Closes #833.

commit6bd686a4f6ab0c1584b0aaff995be57e93c8ed38 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 19 Apr 2013, 23:02 (14 years ago) parent0ee081e
1 file changed+7−1
src/Text/Pandoc/Shared.hs+7−1
src/Text/Pandoc/Shared.hs+7−1
@@ -105,6 +105,7 @@ import Network.HTTP (findHeader, rspBody,
105105import Network.Browser (browse, setAllowRedirects, request)
106106#ifdef EMBED_DATA_FILES
107107import Text.Pandoc.Data (dataFiles)
108+import System.FilePath ( joinPath )
108109#else
109110import Paths_pandoc (getDataFileName)
110111#endif
@@ -521,10 +522,15 @@ inDirectory path action = do
521522readDefaultDataFile :: FilePath -> IO B.ByteString
522523readDefaultDataFile fname =
523524#ifdef EMBED_DATA_FILES
524− case lookup fname dataFiles of
525+ case lookup (makeCanonical fname) dataFiles of
525526 Nothing -> ioError $ userError
526527 $ "Data file `" ++ fname ++ "' does not exist"
527528 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
528534#else
529535 getDataFileName ("data" </> fname) >>= B.readFile
530536#endif