diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-11-01 10:17:00 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-11-01 10:17:00 -0700 |
commit | da87837318cf035be407136b39c5ec6a0009adb4 (patch) | |
tree | d1df7f045a1dfb8a3a57c3e6d9be9ac75d7b3113 /src/Text/Pandoc/Readers | |
parent | 6dff7dccaa08a394231fc99f29723a939c5e1306 (diff) | |
download | pandoc-da87837318cf035be407136b39c5ec6a0009adb4.tar.gz |
LaTeX reader: Added code to handleIncludes to avoid inf loops.
e.g. when one file includes another which includes it.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 22d9b237a..4dce1726e 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -681,16 +681,22 @@ rawEnv name = do -- | Replace "include" commands with file contents. handleIncludes :: String -> IO String -handleIncludes [] = return [] -handleIncludes ('\\':xs) = +handleIncludes = handleIncludes' [] + +-- parents parameter prevents infinite include loops +handleIncludes' :: [FilePath] -> String -> IO String +handleIncludes' _ [] = return [] +handleIncludes' parents ('\\':xs) = case runParser include defaultParserState "input" ('\\':xs) of - Right (fs, rest) -> do yss <- mapM readTeXFile fs - handleIncludes $ intercalate "\n" yss ++ rest + Right (fs, rest) -> do yss <- mapM readTeXFile + [f | f <- fs, f `notElem` parents] + handleIncludes' (parents ++ fs) $ + intercalate "\n" yss ++ rest _ -> case runParser (verbCmd <|> verbatimEnv) defaultParserState - "input" ('\\':xs) of - Right (r, rest) -> (r ++) `fmap` handleIncludes rest - _ -> ('\\':) `fmap` handleIncludes xs -handleIncludes (x:xs) = (x:) `fmap` handleIncludes xs + "input" ('\\':xs) of + Right (r, rest) -> (r ++) `fmap` handleIncludes' parents rest + _ -> ('\\':) `fmap` handleIncludes' parents xs +handleIncludes' parents (x:xs) = (x:) `fmap` handleIncludes' parents xs readTeXFile :: FilePath -> IO String readTeXFile f = do |