aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-09-03 09:39:27 +0200
committerJohn MacFarlane <[email protected]>2025-09-03 09:39:27 +0200
commit6727d2d1771c94a2f09f01e74f5d08b9e0a22c42 (patch)
tree816fa3912fdfb6dc195757e852016a7b70d2925a /src
parente0acb24528cbf409ae5723e537acb0c2ed4e2d91 (diff)
T.P.SelfContained: try fetching relative resources...
...without query or fragment if the original fetch fails. This provides a fix for #1477 in a way that doesn't raise the problems mentioned in #11021.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/SelfContained.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs
index 909a9d2db..e4126171f 100644
--- a/src/Text/Pandoc/SelfContained.hs
+++ b/src/Text/Pandoc/SelfContained.hs
@@ -422,12 +422,19 @@ getData mimetype src
return $ Fetched (mime, result)
handler e = case e of
PandocResourceNotFound r -> do
- report $ CouldNotFetchResource r ""
- return $ CouldNotFetch 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)
+ 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
+ removeQueryAndFragment = T.takeWhile (\c -> c /= '#' && c /= '?')