git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Added code to handleIncludes to avoid inf loops.
da87837John MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+14−8
@@ -681,16 +681,22 @@ rawEnv name = do
681
681
682-- | Replace "include" commands with file contents.
682-- | Replace "include" commands with file contents.
683handleIncludes :: String -> IO String
683handleIncludes :: String -> IO String
684−handleIncludes [] = return []
684+handleIncludes = handleIncludes' []
685+
686+-- parents parameter prevents infinite include loops
687+handleIncludes' :: [FilePath] -> String -> IO String
688+handleIncludes' _ [] = return []
685−handleIncludes ('\\':xs) =
689+handleIncludes' parents ('\\':xs) =
686 case runParser include defaultParserState "input" ('\\':xs) of
690 case runParser include defaultParserState "input" ('\\':xs) of
687− Right (fs, rest) -> do yss <- mapM readTeXFile fs
691+ Right (fs, rest) -> do yss <- mapM readTeXFile
692+ [f | f <- fs, f `notElem` parents]
693+ handleIncludes' (parents ++ fs) $
688− handleIncludes $ intercalate "\n" yss ++ rest
694+ intercalate "\n" yss ++ rest
689 _ -> case runParser (verbCmd <|> verbatimEnv) defaultParserState
695 _ -> case runParser (verbCmd <|> verbatimEnv) defaultParserState
690− "input" ('\\':xs) of
696+ "input" ('\\':xs) of
691− Right (r, rest) -> (r ++) `fmap` handleIncludes rest
697+ Right (r, rest) -> (r ++) `fmap` handleIncludes' parents rest
692− _ -> ('\\':) `fmap` handleIncludes xs
698+ _ -> ('\\':) `fmap` handleIncludes' parents xs
693−handleIncludes (x:xs) = (x:) `fmap` handleIncludes xs
699+handleIncludes' parents (x:xs) = (x:) `fmap` handleIncludes' parents xs
694
700
695readTeXFile :: FilePath -> IO String
701readTeXFile :: FilePath -> IO String
696readTeXFile f = do
702readTeXFile f = do