From 85ff3c57710dc96e4f7e80b51d85f93bffca8a3b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 2 Aug 2014 16:32:11 -0700 Subject: fetchItem: improved mime type guessing. Strip a fragment like `?#iefix` from the extension before doing the mime lookup. --- src/Text/Pandoc/Shared.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index df788425b..9acb959a0 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -775,12 +775,13 @@ fetchItem sourceURL s = Nothing -> openURL s' -- will throw error (Nothing, _) -> E.try readLocalFile -- get from local file system where readLocalFile = do - let mime = case takeExtension s of - ".gz" -> getMimeType $ dropExtension s - x -> getMimeType x - cont <- BS.readFile $ unEscapeString $ dropFragmentAndQuery s + cont <- BS.readFile fp return (cont, mime) dropFragmentAndQuery = takeWhile (\c -> c /= '?' && c /= '#') + fp = unEscapeString $ dropFragmentAndQuery s + mime = case takeExtension fp of + ".gz" -> getMimeType $ dropExtension fp + x -> getMimeType x ensureEscaped = escapeURIString isAllowedInURI -- | Like 'fetchItem', but also looks for items in a 'MediaBag'. -- cgit v1.2.3