git.iko.soy/typeable/pandoc
on master help sign in
More principled fix for #1820.
10e28efJohn MacFarlane
src/Text/Pandoc/Readers/HTML.hs+7−5
@@ -51,7 +51,7 @@ import Text.Pandoc.Options (ReaderOptions(readerParseRaw, readerTrace)
51import Text.Pandoc.Parsing hiding ((<|>))
51import Text.Pandoc.Parsing hiding ((<|>))
52import Text.Pandoc.Walk
52import Text.Pandoc.Walk
53import Data.Maybe ( fromMaybe, isJust)
53import Data.Maybe ( fromMaybe, isJust)
54−import Data.List ( intercalate, isInfixOf )
54+import Data.List ( intercalate, isInfixOf, isPrefixOf )
55import Data.Char ( isDigit )
55import Data.Char ( isDigit )
56import Control.Monad ( liftM, guard, when, mzero, void, unless )
56import Control.Monad ( liftM, guard, when, mzero, void, unless )
57import Control.Arrow ((***))
57import Control.Arrow ((***))
@@ -887,16 +887,18 @@ htmlTag :: Monad m
887 => (Tag String -> Bool)
887 => (Tag String -> Bool)
888 -> ParserT [Char] st m (Tag String, String)
888 -> ParserT [Char] st m (Tag String, String)
889htmlTag f = try $ do
889htmlTag f = try $ do
890− lookAhead $ char '<' >> ((oneOf "/!?" >> nonspaceChar) <|> letter)
890+ lookAhead (char '<')
891+ inp <- getInput
891− (next : _) <- getInput >>= return . canonicalizeTags . parseTags
892+ let (next : _) = canonicalizeTags $ parseTags inp
892 guard $ f next
893 guard $ f next
893− -- advance the parser
894 case next of
894 case next of
895− TagComment s -> do
895+ TagComment s
896+ | "<!--" `isPrefixOf` inp -> do
896 count (length s + 4) anyChar
897 count (length s + 4) anyChar
897 skipMany (satisfy (/='>'))
898 skipMany (satisfy (/='>'))
898 char '>'
899 char '>'
899 return (next, "<!--" ++ s ++ "-->")
900 return (next, "<!--" ++ s ++ "-->")
901+ | otherwise -> fail "bogus comment mode, HTML5 parse error"
900 _ -> do
902 _ -> do
901 rendered <- manyTill anyChar (char '>')
903 rendered <- manyTill anyChar (char '>')
902 return (next, rendered ++ ">")
904 return (next, rendered ++ ">")
tests/Tests/Readers/Markdown.hs+3
@@ -169,6 +169,9 @@ tests = [ testGroup "inline code"
169 "<del>test</del>" =?>
169 "<del>test</del>" =?>
170 rawBlock "html" "<del>" <> plain (str "test") <>
170 rawBlock "html" "<del>" <> plain (str "test") <>
171 rawBlock "html" "</del>"
171 rawBlock "html" "</del>"
172+ , "invalid tag (issue #1820" =:
173+ "</ div></.div>" =?>
174+ para (text "</ div></.div>")
172 ]
175 ]
173 , "unbalanced brackets" =:
176 , "unbalanced brackets" =:
174 "[[[[[[[[[[[[[[[hi" =?> para (text "[[[[[[[[[[[[[[[hi")
177 "[[[[[[[[[[[[[[[hi" =?> para (text "[[[[[[[[[[[[[[[hi")