T.P.Class.IO.openURL improvements for data uris.

- Only treat as base64 if ';base64' is present.
- Otherwise treat as UTF-8 (not 100% reliable but should cover most
  other cases).
- Strip off ';base64' (or ';charset=...' or whatever) from mime type.

This last change addresses #9195 (problems with data URIs in
conversion to docx).
This commit is contained in:
John MacFarlane
2023-11-17 10:13:22 -08:00
parent 3591733e19
commit 1880d75e7c
+6 -2
View File
@@ -124,9 +124,13 @@ openURL :: (PandocMonad m, MonadIO m) => Text -> m (B.ByteString, Maybe MimeType
openURL u
| Just (URI{ uriScheme = "data:",
uriPath = upath }) <- parseURI (T.unpack u) = do
let (mime, rest) = break (== ',') $ unEscapeString upath
let (mimespec, rest) = break (== ',') $ unEscapeString upath
let contents = UTF8.fromString $ drop 1 rest
return (decodeBase64Lenient contents, Just (T.pack mime))
case break (== ';') (filter (/= ' ') mimespec) of
(mime, ";base64") ->
return (decodeBase64Lenient contents, Just (T.pack mime))
(mime, _) ->
return (contents, Just (T.pack mime))
| otherwise = do
let toReqHeader (n, v) = (CI.mk (UTF8.fromText n), UTF8.fromText v)
customHeaders <- map toReqHeader <$> getsCommonState stRequestHeaders