git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: fix bad handling of empty src attribute in iframe.

- If src is empty, we simply skip the iframe. - If src is invalid or cannot be fetched, we issue a warning and skip instead of failing with an error. - Closes #7099.

commitd84a6041e12547331f3a252ea4e8b4d229ba1159 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 13 Feb 2021, 13:06 (6 years ago) parent6e73273
2 files changed+24−8
src/Text/Pandoc/Readers/HTML.hs+12−6 test/command/7099.md+12−2
src/Text/Pandoc/Readers/HTML.hs+12−6
@@ -26,7 +26,7 @@ module Text.Pandoc.Readers.HTML ( readHtml
2626
2727import Control.Applicative ((<|>))
2828import Control.Monad (guard, msum, mzero, unless, void)
29−import Control.Monad.Except (throwError)
29+import Control.Monad.Except (throwError, catchError)
3030import Control.Monad.Reader (ask, asks, lift, local, runReaderT)
3131import Data.ByteString.Base64 (encode)
3232import Data.Char (isAlphaNum, isLetter)
@@ -393,11 +393,17 @@ pIframe = try $ do
393393 tag <- pSatisfy (tagOpen (=="iframe") (isJust . lookup "src"))
394394 pCloses "iframe" <|> eof
395395 url <- canonicalizeUrl $ fromAttrib "src" tag
396− (bs, _) <- openURL url
397− let inp = UTF8.toText bs
398− opts <- readerOpts <$> getState
399− Pandoc _ contents <- readHtml opts inp
400− return $ B.divWith ("",["iframe"],[]) $ B.fromList contents
396+ if T.null url
397+ then ignore $ renderTags' [tag, TagClose "iframe"]
398+ else catchError
399+ (do (bs, _) <- openURL url
400+ let inp = UTF8.toText bs
401+ opts <- readerOpts <$> getState
402+ Pandoc _ contents <- readHtml opts inp
403+ return $ B.divWith ("",["iframe"],[]) $ B.fromList contents)
404+ (\e -> do
405+ logMessage $ CouldNotFetchResource url (renderError e)
406+ ignore $ renderTags' [tag, TagClose "iframe"])
401407
402408pRawHtmlBlock :: PandocMonad m => TagParser m Blocks
403409pRawHtmlBlock = do
test/command/7099.md+12−2
@@ -2,7 +2,17 @@
22% pandoc -f html -t native --verbose
33<iframe src=""></iframe>
44^D
5−[INFO] Fetching ...
6−[INFO] Skipped '<iframe src></iframe>' at input line 1 column 1
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
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"
16+[INFO] Skipped '<iframe src="h:invalid@url"></iframe>' at input line 1 column 29
717[]
818```