git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: fix bad handling of empty src attribute in iframe.
d84a604John MacFarlane
src/Text/Pandoc/Readers/HTML.hs+12−6
@@ -26,7 +26,7 @@ module Text.Pandoc.Readers.HTML ( readHtml
26
26
27import Control.Applicative ((<|>))
27import Control.Applicative ((<|>))
28import Control.Monad (guard, msum, mzero, unless, void)
28import Control.Monad (guard, msum, mzero, unless, void)
29−import Control.Monad.Except (throwError)
29+import Control.Monad.Except (throwError, catchError)
30import Control.Monad.Reader (ask, asks, lift, local, runReaderT)
30import Control.Monad.Reader (ask, asks, lift, local, runReaderT)
31import Data.ByteString.Base64 (encode)
31import Data.ByteString.Base64 (encode)
32import Data.Char (isAlphaNum, isLetter)
32import Data.Char (isAlphaNum, isLetter)
@@ -393,11 +393,17 @@ pIframe = try $ do
393 tag <- pSatisfy (tagOpen (=="iframe") (isJust . lookup "src"))
393 tag <- pSatisfy (tagOpen (=="iframe") (isJust . lookup "src"))
394 pCloses "iframe" <|> eof
394 pCloses "iframe" <|> eof
395 url <- canonicalizeUrl $ fromAttrib "src" tag
395 url <- canonicalizeUrl $ fromAttrib "src" tag
396+ if T.null url
397+ then ignore $ renderTags' [tag, TagClose "iframe"]
398+ else catchError
396− (bs, _) <- openURL url
399+ (do (bs, _) <- openURL url
397− let inp = UTF8.toText bs
400+ let inp = UTF8.toText bs
398− opts <- readerOpts <$> getState
401+ opts <- readerOpts <$> getState
399− Pandoc _ contents <- readHtml opts inp
402+ Pandoc _ contents <- readHtml opts inp
400− return $ B.divWith ("",["iframe"],[]) $ B.fromList contents
403+ return $ B.divWith ("",["iframe"],[]) $ B.fromList contents)
404+ (\e -> do
405+ logMessage $ CouldNotFetchResource url (renderError e)
406+ ignore $ renderTags' [tag, TagClose "iframe"])
401
407
402pRawHtmlBlock :: PandocMonad m => TagParser m Blocks
408pRawHtmlBlock :: PandocMonad m => TagParser m Blocks
403pRawHtmlBlock = do
409pRawHtmlBlock = do
test/command/7099.md+12−2
@@ -2,7 +2,17 @@
2% pandoc -f html -t native --verbose
2% pandoc -f html -t native --verbose
3<iframe src=""></iframe>
3<iframe src=""></iframe>
4^D
4^D
5+[INFO] Skipped '<iframe src></iframe>' at input line 1 column 16
6+[]
7+```
8+
9+```
10+% pandoc -f html -t native --verbose
11+<iframe src="h:invalid@url"></iframe>
12+^D
5−[INFO] Fetching ...
13+[INFO] Fetching h:invalid@url...
14+[WARNING] Could not fetch resource 'h:invalid@url': Could not fetch h:invalid@url
15+ InvalidUrlException "h:invalid@url" "Invalid scheme"
6−[INFO] Skipped '<iframe src></iframe>' at input line 1 column 1
16+[INFO] Skipped '<iframe src="h:invalid@url"></iframe>' at input line 1 column 29
7[]
17[]
8```
18```