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.
This commit is contained in:
parent
0ee081ef25
commit
6bd686a4f6
1 changed files with 7 additions and 1 deletions
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue