From 226f765e762dba2c0ba60e98998cfab2a9e6d2b0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 4 Sep 2025 13:32:05 +0200 Subject: Revision of query/fragment dropping fix to #11021. --- src/Text/Pandoc/SelfContained.hs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index e4126171f..330dddff2 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -43,7 +43,6 @@ import Data.Either (lefts, rights) import Data.Maybe (isNothing) import qualified Data.Map as M import Control.Monad.State --- import Debug.Trace isOk :: Char -> Bool isOk c = isAscii c && isAlphaNum c @@ -420,25 +419,23 @@ getData mimetype src return res else return raw' return $ Fetched (mime, result) - handler e = case e of - PandocResourceNotFound r -> do - -- If fetch failed and we have a fragment and/or query, - -- try the fetch again without these, since the resource - -- may be local (see #1477, #11021) - if T.any (\c -> c == '?' || c == '#') src && not (isURI src) - then getData mimetype (removeQueryAndFragment src) - else do - report $ CouldNotFetchResource r "" - return $ CouldNotFetch e - PandocHttpError u er -> do - report $ CouldNotFetchResource u (tshow er) - return $ CouldNotFetch e - _ -> throwError e + handler e + -- If fetch failed and we have a fragment and/or query, + -- try the fetch again without these, since the resource + -- may be local (see #1477, #11021) + | T.any (\c -> c == '?' || c == '#') src && not (isURI src) + = getData mimetype (removeQueryAndFragment src) + | otherwise + = case e of + PandocResourceNotFound r -> do + report $ CouldNotFetchResource r "" + return $ CouldNotFetch e + PandocHttpError u er -> do + report $ CouldNotFetchResource u (tshow er) + return $ CouldNotFetch e + _ -> throwError e removeQueryAndFragment = T.takeWhile (\c -> c /= '#' && c /= '?') - - - -- | Convert HTML into self-contained HTML, incorporating images, -- scripts, and CSS using data: URIs. makeSelfContained :: PandocMonad m => T.Text -> m T.Text -- cgit v1.2.3