mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-28 11:16:33 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user