epub-metadata 2.3.1 → 2.3.2
raw patch · 20 files changed
+93/−22 lines, 20 filessetup-changedPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Codec.Epub.IO: removeIllegalStartChars :: String -> String
Files
- LICENSE +1/−1
- Setup.hs +1/−1
- epub-metadata.cabal +2/−2
- src/Codec/Epub/Archive.hs +1/−1
- src/Codec/Epub/IO.hs +10/−2
- src/Codec/Epub/Opf/Common.hs +1/−1
- src/Codec/Epub/Opf/Format/Guide.hs +1/−1
- src/Codec/Epub/Opf/Format/Manifest.hs +1/−1
- src/Codec/Epub/Opf/Format/Metadata.hs +1/−1
- src/Codec/Epub/Opf/Format/Package.hs +1/−1
- src/Codec/Epub/Opf/Format/Spine.hs +1/−1
- src/Codec/Epub/Opf/Format/Util.hs +1/−1
- src/Codec/Epub/Opf/Package.hs +1/−1
- src/Codec/Epub/Opf/Package/Guide.hs +1/−1
- src/Codec/Epub/Opf/Package/Manifest.hs +1/−1
- src/Codec/Epub/Opf/Package/Metadata.hs +1/−1
- src/Codec/Epub/Opf/Package/Spine.hs +1/−1
- src/Codec/Epub/Opf/Parse.hs +3/−2
- testsuite/opf-parse.hs +45/−1
- testsuite/testIllegalCharsBeforeDecl.opf +18/−0
LICENSE view
@@ -1,4 +1,4 @@-Copyright Dino Morelli 2010-2012+Copyright Dino Morelli 2010-2013 All rights reserved.
Setup.hs view
@@ -1,6 +1,6 @@ #! /usr/bin/env runhaskell --- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
epub-metadata.cabal view
@@ -1,10 +1,10 @@ name: epub-metadata-version: 2.3.1+version: 2.3.2 cabal-version: >= 1.8 build-type: Simple license: BSD3 license-file: LICENSE-copyright: 2010-2012 Dino Morelli+copyright: 2010-2013 Dino Morelli author: Dino Morelli maintainer: Dino Morelli <dino@ui3.info> stability: stable
src/Codec/Epub/Archive.hs view
@@ -1,4 +1,4 @@--- Copyright: 2011-2012 Dino Morelli+-- Copyright: 2011-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/IO.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -10,6 +10,7 @@ ( opfContentsFromZip , opfContentsFromBS , opfContentsFromDir+ , removeIllegalStartChars , removeEncoding , removeDoctype )@@ -30,10 +31,17 @@ import Text.XML.HXT.Arrow.ReadDocument ( readString ) +-- | An evil hack to remove *ILLEGAL* characters before the XML+-- | declaration. Why do people write software that does this?+-- | Can't they follow directions?+removeIllegalStartChars :: String -> String+removeIllegalStartChars = dropWhile (/= '<')++ -- | An evil hack to remove encoding from the document removeEncoding :: String -> String removeEncoding = flip (subRegex - (mkRegexWithOpts " +encoding=\"UTF-8\"" False True)) ""+ (mkRegexWithOpts " +encoding=\"UTF-8\"" False False)) "" -- | An evil hack to remove any <!DOCTYPE ...> from the document
src/Codec/Epub/Opf/Common.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Format/Guide.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Format/Manifest.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Format/Metadata.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Format/Package.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Format/Spine.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Format/Util.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Package.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Package/Guide.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Package/Manifest.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Package/Metadata.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Package/Spine.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/Codec/Epub/Opf/Parse.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -255,7 +255,8 @@ parseXmlToOpf contents = do {- Improper encoding and schema declarations have been causing havok with this parse, cruelly strip them out. -}- let cleanedContents = removeEncoding . removeDoctype $ contents+ let cleanedContents = removeIllegalStartChars . removeEncoding+ . removeDoctype $ contents result <- liftIO $ runX ( readString [withValidate no] cleanedContents
testsuite/opf-parse.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -33,6 +33,7 @@ , testMinimal , testMissingAll , testDamagedZip+ , testIllegalCharsBeforeDecl ] @@ -206,3 +207,46 @@ actual <- runErrorT $ opfContentsFromZip $ "testsuite" </> "damagedZipCentralDir.epub" actual @?= Left "Did not find end of central directory signature. Failed reading at byte position 138"+++{- Found books coming from Barnes & Noble (for their NOOK reader) to+ contain illegal characters before the XML declaration. This is+ strictly not allowed by the XML specification. I am very+ disappointed with Barnes & Noble for selling garbage like this.+-}+testIllegalCharsBeforeDecl :: Test+testIllegalCharsBeforeDecl = TestCase $ do+ xmlString <- readFile $+ "testsuite" </> "testIllegalCharsBeforeDecl.opf"+ actual <- runErrorT $ parseXmlToOpf xmlString+ let expected =+ Right Package+ { opVersion = "2.0"+ , opUniqueId = "uuid_id"+ , opMeta = Metadata+ { metaTitles = [MetaTitle Nothing "Foo Bar Baz"]+ , metaCreators = []+ , metaContributors = []+ , metaSubjects = []+ , metaDescription = Nothing+ , metaPublisher = Nothing+ , metaDates = []+ , metaType = Nothing+ , metaFormat = Nothing+ , metaIds = [MetaId "uuid_id" (Just "uuid") "1122334455"]+ , metaSource = Nothing+ , metaLangs = ["en"]+ , metaRelation = Nothing+ , metaCoverage = Nothing+ , metaRights = Nothing}+ , opManifest =+ [ ManifestItem+ { mfiId = "ncx"+ , mfiHref = "toc.ncx"+ , mfiMediaType = "application/x-dtbncx+xml"+ }+ ]+ , opSpine = Spine {spineToc = "ncx", spineItemrefs = []}+ , opGuide = []+ }+ assertEqual "illegal chars before XML declaration" expected actual
+ testsuite/testIllegalCharsBeforeDecl.opf view
@@ -0,0 +1,18 @@+<?xml version="1.0" encoding="utf-8"?> +<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="uuid_id"> + <opf:metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata" xmlns:dc="http://purl.org/dc/elements/1.1/"> + <dc:language>en</dc:language> + <dc:title>Foo Bar Baz</dc:title> + <dc:identifier id="uuid_id" opf:scheme="uuid">1122334455</dc:identifier> + </opf:metadata> + + <manifest> + <item id="ncx" + href="toc.ncx" + media-type="application/x-dtbncx+xml" /> + </manifest> + + <spine toc="ncx"> + </spine> + +</package>