Skip to content

Commit

Permalink
Shared: readDefaultDataFile: normalize the paths.
Browse files Browse the repository at this point in the history
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 jgm#833.
  • Loading branch information
jgm committed Apr 20, 2013
1 parent 0ee081e commit 6bd686a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Text/Pandoc/Shared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import Network.HTTP (findHeader, rspBody,
import Network.Browser (browse, setAllowRedirects, request)
#ifdef EMBED_DATA_FILES
import Text.Pandoc.Data (dataFiles)
import System.FilePath ( joinPath )
#else
import Paths_pandoc (getDataFileName)
#endif
Expand Down Expand Up @@ -521,10 +522,15 @@ inDirectory path action = do
readDefaultDataFile :: FilePath -> IO B.ByteString
readDefaultDataFile fname =
#ifdef EMBED_DATA_FILES
case lookup fname dataFiles of
case lookup (makeCanonical fname) dataFiles of
Nothing -> ioError $ userError
$ "Data file `" ++ fname ++ "' does not exist"
Just contents -> return contents
where makeCanonical = joinPath . transformPathParts . splitBy (=='/')
transformPathParts = reverse . foldl go []
go as "." = as
go (_:as) ".." = as
go as x = x : as
#else
getDataFileName ("data" </> fname) >>= B.readFile
#endif
Expand Down

0 comments on commit 6bd686a

Please sign in to comment.