git.iko.soy/typeable/pandoc
on master help sign in
More principled fix for #1820.

If the tag parses as a comment, we check to see if the input starts with `<!--`. If not, it's bogus comment mode and we fail htmlTag. Includes test case. Closes #1820.

commit10e28ef750f0c7e6bc0dfb7aabaaad8edf059e3c authorJohn MacFarlane <jgm@berkeley.edu> dateFri 17 Apr 2015, 22:55 (12 years ago) parentaaf5e67
2 files changed+10−5
src/Text/Pandoc/Readers/HTML.hs+7−5 tests/Tests/Readers/Markdown.hs+3
src/Text/Pandoc/Readers/HTML.hs+7−5
@@ -51,7 +51,7 @@ import Text.Pandoc.Options (ReaderOptions(readerParseRaw, readerTrace)
5151import Text.Pandoc.Parsing hiding ((<|>))
5252import Text.Pandoc.Walk
5353import Data.Maybe ( fromMaybe, isJust)
54−import Data.List ( intercalate, isInfixOf )
54+import Data.List ( intercalate, isInfixOf, isPrefixOf )
5555import Data.Char ( isDigit )
5656import Control.Monad ( liftM, guard, when, mzero, void, unless )
5757import Control.Arrow ((***))
@@ -887,16 +887,18 @@ htmlTag :: Monad m
887887 => (Tag String -> Bool)
888888 -> ParserT [Char] st m (Tag String, String)
889889htmlTag f = try $ do
890− lookAhead $ char '<' >> ((oneOf "/!?" >> nonspaceChar) <|> letter)
891− (next : _) <- getInput >>= return . canonicalizeTags . parseTags
890+ lookAhead (char '<')
891+ inp <- getInput
892+ let (next : _) = canonicalizeTags $ parseTags inp
892893 guard $ f next
893− -- advance the parser
894894 case next of
895− TagComment s -> do
895+ TagComment s
896+ | "<!--" `isPrefixOf` inp -> do
896897 count (length s + 4) anyChar
897898 skipMany (satisfy (/='>'))
898899 char '>'
899900 return (next, "<!--" ++ s ++ "-->")
901+ | otherwise -> fail "bogus comment mode, HTML5 parse error"
900902 _ -> do
901903 rendered <- manyTill anyChar (char '>')
902904 return (next, rendered ++ ">")
tests/Tests/Readers/Markdown.hs+3
@@ -169,6 +169,9 @@ tests = [ testGroup "inline code"
169169 "<del>test</del>" =?>
170170 rawBlock "html" "<del>" <> plain (str "test") <>
171171 rawBlock "html" "</del>"
172+ , "invalid tag (issue #1820" =:
173+ "</ div></.div>" =?>
174+ para (text "</ div></.div>")
172175 ]
173176 , "unbalanced brackets" =:
174177 "[[[[[[[[[[[[[[[hi" =?> para (text "[[[[[[[[[[[[[[[hi")