diff options
| author | John MacFarlane <[email protected]> | 2023-12-06 08:04:24 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-12-06 08:05:53 -0800 |
| commit | 8b523749aebb67f709fe7348b412f3e5e629ceb4 (patch) | |
| tree | f756b53fa6dd93938e54379c4e857e8dfe0281b7 | |
| parent | dbbd70d4f8f5bc21fbb779a177a0a4901c02b9fb (diff) | |
Revert "Use base64 instead of base64-bytestring."
This reverts commit 6625e9655ed2bb0c4bd4dd91b5959a103deab1cb.
base64 is currently buggy on 32-bit systems. Closes #9233.
| -rw-r--r-- | pandoc.cabal | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Class/IO.hs | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/FB2.hs | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 5 | ||||
| -rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 4 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/FB2.hs | 6 |
6 files changed, 13 insertions, 12 deletions
diff --git a/pandoc.cabal b/pandoc.cabal index 21af0f2ff..4f199f58d 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -468,6 +468,7 @@ library aeson-pretty >= 0.8.9 && < 0.9, array >= 0.5 && < 0.6, attoparsec >= 0.12 && < 0.15, + base64-bytestring >= 0.1 && < 1.3, binary >= 0.7 && < 0.11, blaze-html >= 0.9 && < 0.10, blaze-markup >= 0.8 && < 0.9, @@ -484,7 +485,6 @@ library directory >= 1.2.3 && < 1.4, doclayout >= 0.4.0.1 && < 0.5, doctemplates >= 0.11 && < 0.12, - base64 >= 0.4 && < 0.5, emojis >= 0.1 && < 0.2, exceptions >= 0.8 && < 0.11, file-embed >= 0.0 && < 0.1, diff --git a/src/Text/Pandoc/Class/IO.hs b/src/Text/Pandoc/Class/IO.hs index 760990129..4ede6df10 100644 --- a/src/Text/Pandoc/Class/IO.hs +++ b/src/Text/Pandoc/Class/IO.hs @@ -37,7 +37,7 @@ module Text.Pandoc.Class.IO import Control.Monad.Except (throwError) import Control.Monad.IO.Class (MonadIO, liftIO) -import Data.ByteString.Base64 (decodeBase64Lenient) +import Data.ByteString.Base64 (decodeLenient) import Data.ByteString.Lazy (toChunks) import Data.Text (Text, pack, unpack) import Data.Time (TimeZone, UTCTime) @@ -128,7 +128,7 @@ openURL u let contents = UTF8.fromString $ drop 1 rest case break (== ';') (filter (/= ' ') mimespec) of (mime, ";base64") -> - return (decodeBase64Lenient contents, Just (T.pack mime)) + return (decodeLenient contents, Just (T.pack mime)) (mime, _) -> return (contents, Just (T.pack mime)) | otherwise = do diff --git a/src/Text/Pandoc/Readers/FB2.hs b/src/Text/Pandoc/Readers/FB2.hs index 2844c9266..8f5a75418 100644 --- a/src/Text/Pandoc/Readers/FB2.hs +++ b/src/Text/Pandoc/Readers/FB2.hs @@ -25,7 +25,7 @@ TODO: module Text.Pandoc.Readers.FB2 ( readFB2 ) where import Control.Monad.Except (throwError) import Control.Monad.State.Strict -import Data.ByteString.Lazy.Base64 +import Data.ByteString.Base64.Lazy import Data.Functor import Data.List (intersperse) import qualified Data.Map as M @@ -202,7 +202,7 @@ parseBinaryElement e = report $ IgnoredElement "binary without content-type attribute" (Just filename, contentType) -> insertMedia (T.unpack filename) contentType - (decodeBase64Lenient + (decodeLenient (UTF8.fromTextLazy . TL.fromStrict . strContent $ e)) -- * Type parsers diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 42e12c419..475c3fff2 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -28,7 +28,7 @@ import Control.Applicative ((<|>)) import Control.Monad (guard, mzero, unless, void) import Control.Monad.Except (throwError, catchError) import Control.Monad.Reader (ask, asks, lift, local, runReaderT) -import Data.Text.Encoding.Base64 (encodeBase64) +import Data.ByteString.Base64 (encode) import Data.Char (isAlphaNum, isLetter) import Data.Default (Default (..), def) import Data.Foldable (for_) @@ -807,7 +807,8 @@ pSvg = do contents <- many (notFollowedBy (pCloses "svg") >> pAny) closet <- TagClose "svg" <$ (pCloses "svg" <|> eof) let rawText = T.strip $ renderTags' (opent : contents ++ [closet]) - let svgData = "data:image/svg+xml;base64," <> encodeBase64 rawText + let svgData = "data:image/svg+xml;base64," <> + UTF8.toText (encode $ UTF8.fromText rawText) return $ B.imageWith (ident,cls,[]) svgData mempty mempty pCodeWithClass :: PandocMonad m => Text -> Text -> TagParser m Inlines diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index dccf1b999..7a39edc22 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -19,7 +19,7 @@ module Text.Pandoc.SelfContained ( makeDataURI, makeSelfContained ) where import Codec.Compression.GZip as Gzip import Control.Applicative ((<|>)) import Data.ByteString (ByteString) -import Data.ByteString.Base64 (encodeBase64) +import Data.ByteString.Base64 (encode) import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy as L import qualified Data.Text as T @@ -52,7 +52,7 @@ makeDataURI :: (MimeType, ByteString) -> T.Text makeDataURI (mime, raw) = if textual then "data:" <> mime' <> "," <> T.pack (escapeURIString isOk (toString raw)) - else "data:" <> mime' <> ";base64," <> encodeBase64 raw + else "data:" <> mime' <> ";base64," <> toText (encode raw) where textual = "text/" `T.isPrefixOf` mime mime' = if textual && T.any (== ';') mime then mime <> ";charset=utf-8" diff --git a/src/Text/Pandoc/Writers/FB2.hs b/src/Text/Pandoc/Writers/FB2.hs index 7e62f2a5a..f92832538 100644 --- a/src/Text/Pandoc/Writers/FB2.hs +++ b/src/Text/Pandoc/Writers/FB2.hs @@ -21,16 +21,16 @@ module Text.Pandoc.Writers.FB2 (writeFB2) where import Control.Monad (zipWithM, liftM) import Control.Monad.Except (catchError, throwError) import Control.Monad.State.Strict (StateT, evalStateT, get, gets, lift, modify) -import Data.ByteString.Base64 (encodeBase64) +import Data.ByteString.Base64 (encode) import Data.Char (isAscii, isControl, isSpace) import Data.Either (lefts, rights) import Data.List (intercalate) import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Lazy as TL +import qualified Data.Text.Encoding as TE import Text.Pandoc.URI (urlEncode, isURI) import Text.Pandoc.XML.Light as X - import Text.Pandoc.Class.PandocMonad (PandocMonad, report) import qualified Text.Pandoc.Class.PandocMonad as P import Text.Pandoc.Definition @@ -237,7 +237,7 @@ fetchImage href link = do report $ CouldNotDetermineMimeType link return Nothing Just mime -> return $ Just (mime, - encodeBase64 bs)) + TE.decodeUtf8 $ encode bs)) (\e -> do report $ CouldNotFetchResource link (tshow e) return Nothing) |
