git.iko.soy/typeable/pandoc
on master help sign in
Binary fmts throw PandocError on zip-archive fail

Commit 91dc3342 made `readDocx` throw PandocError if there was an unarchiving error. This extends that fix to `readOdt` and `readEPUB`.

commit99eac312feb258ac4129c923e5b4fde57da9fbc3 authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 1 May 2016, 17:40 (10 years ago) parent1fbe79d
2 files changed+7−3
src/Text/Pandoc/Readers/EPUB.hs+4−2 src/Text/Pandoc/Readers/Odt.hs+3−1
src/Text/Pandoc/Readers/EPUB.hs+4−2
@@ -19,7 +19,7 @@ import Text.Pandoc.Compat.Except (MonadError, throwError, runExcept, Except)
1919import Text.Pandoc.Compat.Monoid ((<>))
2020import Text.Pandoc.MIME (MimeType)
2121import qualified Text.Pandoc.Builder as B
22−import Codec.Archive.Zip ( Archive (..), toArchive, fromEntry
22+import Codec.Archive.Zip ( Archive (..), toArchiveOrFail, fromEntry
2323 , findEntryByPath, Entry)
2424import qualified Data.ByteString.Lazy as BL (ByteString)
2525import System.FilePath ( takeFileName, (</>), dropFileName, normalise
@@ -39,7 +39,9 @@ import Text.Pandoc.Error
3939type Items = M.Map String (FilePath, MimeType)
4040
4141readEPUB :: ReaderOptions -> BL.ByteString -> Either PandocError (Pandoc, MediaBag)
42−readEPUB opts bytes = runEPUB (archiveToEPUB opts $ toArchive bytes)
42+readEPUB opts bytes = case toArchiveOrFail bytes of
43+ Right archive -> runEPUB $ archiveToEPUB opts $ archive
44+ Left _ -> Left $ ParseFailure "Couldn't extract ePub file"
4345
4446runEPUB :: Except PandocError a -> Either PandocError a
4547runEPUB = runExcept
src/Text/Pandoc/Readers/Odt.hs+3−1
@@ -59,7 +59,9 @@ readOdt _ bytes = case bytesToOdt bytes of
5959
6060--
6161bytesToOdt :: B.ByteString -> Either PandocError Pandoc
62−bytesToOdt bytes = archiveToOdt $ toArchive bytes
62+bytesToOdt bytes = case toArchiveOrFail bytes of
63+ Right archive -> archiveToOdt archive
64+ Left _ -> Left $ ParseFailure "Couldn't parse odt file."
6365
6466--
6567archiveToOdt :: Archive -> Either PandocError Pandoc