diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-04-19 23:02:38 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-04-19 23:03:59 -0700 |
commit | 6bd686a4f6ab0c1584b0aaff995be57e93c8ed38 (patch) | |
tree | 82476946e3cd6e08f233ac8c7b78a8579df156c5 /src/Text/Pandoc | |
parent | 0ee081ef25bd25594da95378ecd191d1ca9f5239 (diff) | |
download | pandoc-6bd686a4f6ab0c1584b0aaff995be57e93c8ed38.tar.gz |
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 4cca80eda..001af6c6d 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -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 |