[Libreoffice-commits] core.git: external/libepubgen writerperfect/qa writerperfect/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Aug 25 07:26:10 UTC 2017


 external/libepubgen/libepubgen-epub3.patch.1            |   77 ++++++++++++++++
 writerperfect/qa/unit/EPUBExportTest.cxx                |   36 ++++++-
 writerperfect/qa/unit/data/writer/epubexport/hello.fodt |    8 +
 writerperfect/source/writer/EPUBPackage.cxx             |    5 +
 4 files changed, 120 insertions(+), 6 deletions(-)

New commits:
commit 8d411f38badc7adc61fdfc5c08fdbda247bce37a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Aug 24 18:08:11 2017 +0200

    EPUB export: make sure that the mimetype stream is not compressed
    
    Similar to ODF, the spec mandates this, and recent enough epubcheck
    validator asserts this.
    
    Also backport 2 libepubgen commits that fix other validator errors
    around missing mimetypes / malformed URLs.
    
    Change-Id: I29f0524465a30d26585cea92ec27bd336f6a17d8
    Reviewed-on: https://gerrit.libreoffice.org/41526
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/external/libepubgen/libepubgen-epub3.patch.1 b/external/libepubgen/libepubgen-epub3.patch.1
index 14675692846c..52070425d7c0 100644
--- a/external/libepubgen/libepubgen-epub3.patch.1
+++ b/external/libepubgen/libepubgen-epub3.patch.1
@@ -1726,3 +1726,80 @@ index 40c507e..019404f 100644
 -- 
 2.12.3
 
+From 89ae3e392890b9360d271f1c1796cb27e36be26f Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos at collabora.co.uk>
+Date: Thu, 24 Aug 2017 17:11:17 +0200
+Subject: [PATCH] EPUBTextGenerator: empty mime type is the same as no mime
+ type
+
+epubcheck says:
+
+	ERROR(RSC-005): image.epub/OEBPS/content.opf(11,69): Error while parsing file: value of attribute "media-type" is invalid; must be a string matching the regular expression "[a-zA-Z0-9!#$&+\-\^_]+/[a-zA-Z0-9!#$&+\-\^_]+.*"
+---
+ src/lib/EPUBTextGenerator.cpp      |  2 +-
+ src/test/EPUBTextGeneratorTest.cpp | 24 ++++++++++++++++++++++++
+ 2 files changed, 25 insertions(+), 1 deletion(-)
+
+diff --git a/src/lib/EPUBTextGenerator.cpp b/src/lib/EPUBTextGenerator.cpp
+index a39f266..0f7f1e0 100644
+--- a/src/lib/EPUBTextGenerator.cpp
++++ b/src/lib/EPUBTextGenerator.cpp
+@@ -614,7 +614,7 @@ void EPUBTextGenerator::insertBinaryObject(const librevenge::RVNGPropertyList &p
+       newPropList.insert(iter.key(), iter()->clone());
+   }
+ 
+-  if (!mimetype || !data)
++  if (!mimetype || mimetype->getStr().empty() || !data)
+   {
+     EPUBGEN_DEBUG_MSG(("invalid binary object dropped"));
+     return;
+-- 
+2.12.3
+
+From 28e5e30c20aba54dff6505df4c03d6a3da0ee0f3 Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos at collabora.co.uk>
+Date: Thu, 24 Aug 2017 17:41:49 +0200
+Subject: [PATCH] EPUBHTMLGenerator: sanitize URLs a bit in openLink()
+
+epubcheck warns on this:
+
+	WARNING(RSC-023): large.epub/OEBPS/sections/section0018.xhtml(2,5171): The URL 'https:///www.fsf.org' is missing 1 slash(es) '/' after the protocol 'https:'
+---
+ configure.ac                       |  1 +
+ src/lib/EPUBHTMLGenerator.cpp      | 12 +++++++++++-
+ src/test/EPUBTextGeneratorTest.cpp | 40 ++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 52 insertions(+), 1 deletion(-)
+
+diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp
+index 019404f..aa09332 100644
+--- a/src/lib/EPUBHTMLGenerator.cpp
++++ b/src/lib/EPUBHTMLGenerator.cpp
+@@ -12,6 +12,8 @@
+ #include <stack>
+ #include <string>
+ 
++#include <boost/algorithm/string/replace.hpp>
++
+ #include "EPUBHTMLGenerator.h"
+ #include "EPUBImageManager.h"
+ #include "EPUBListStyleManager.h"
+@@ -625,7 +627,15 @@ void EPUBHTMLGenerator::openLink(const RVNGPropertyList &propList)
+   }
+   RVNGPropertyList attrs;
+   if (propList["xlink:href"])
+-    attrs.insert("href", propList["xlink:href"]->getStr().cstr());
++  {
++    std::string href(propList["xlink:href"]->getStr().cstr());
++
++    // Basic URL sanitization.
++    boost::replace_all(href, "http:///", "http://");
++    boost::replace_all(href, "https:///", "https://");
++
++    attrs.insert("href", href.c_str());
++  }
+   m_impl->output(false).openElement("a", attrs);
+ }
+ 
+-- 
+2.12.3
+
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index ef65012daca9..ab1ca51c855b 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -30,14 +30,18 @@ class EPUBExportTest : public test::BootstrapFixture, public unotest::MacrosTest
 {
     uno::Reference<uno::XComponentContext> mxComponentContext;
     uno::Reference<lang::XComponent> mxComponent;
+    utl::TempFile maTempFile;
 
 public:
     virtual void setUp() override;
     virtual void tearDown() override;
+    void createDoc(const OUString &rFile);
     void testOutlineLevel();
+    void testMimetype();
 
     CPPUNIT_TEST_SUITE(EPUBExportTest);
     CPPUNIT_TEST(testOutlineLevel);
+    CPPUNIT_TEST(testMimetype);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -57,28 +61,48 @@ void EPUBExportTest::tearDown()
     test::BootstrapFixture::tearDown();
 }
 
-void EPUBExportTest::testOutlineLevel()
+void EPUBExportTest::createDoc(const OUString &rFile)
 {
     // Import the bugdoc and export as EPUB.
-    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "outline-level.fodt";
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFile;
     mxComponent = loadFromDesktop(aURL);
     CPPUNIT_ASSERT(mxComponent.is());
 
     uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
-    utl::TempFile aTempFile;
-    aTempFile.EnableKillingFile();
+    maTempFile.EnableKillingFile();
     utl::MediaDescriptor aMediaDescriptor;
     aMediaDescriptor["FilterName"] <<= OUString("EPUB");
-    xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+    xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+}
+
+void EPUBExportTest::testOutlineLevel()
+{
+    createDoc("outline-level.fodt");
 
     // Make sure that the output is split into two.
-    uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, aTempFile.GetURL());
+    uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, maTempFile.GetURL());
     CPPUNIT_ASSERT(xNameAccess->hasByName("OEBPS/sections/section0001.xhtml"));
     // This failed, output was a single section.
     CPPUNIT_ASSERT(xNameAccess->hasByName("OEBPS/sections/section0002.xhtml"));
     CPPUNIT_ASSERT(!xNameAccess->hasByName("OEBPS/sections/section0003.xhtml"));
 }
 
+void EPUBExportTest::testMimetype()
+{
+    createDoc("hello.fodt");
+
+    // Check that the mime type is written uncompressed at the expected location.
+    SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
+    SvMemoryStream aMemoryStream;
+    aMemoryStream.WriteStream(aFileStream);
+    OString aExpected("application/epub+zip");
+    CPPUNIT_ASSERT(aMemoryStream.GetSize() > static_cast<sal_uInt64>(38 + aExpected.getLength()));
+
+    OString aActual(static_cast<const char *>(aMemoryStream.GetBuffer()) + 38, aExpected.getLength());
+    // This failed: actual data was some garbage, not the uncompressed mime type.
+    CPPUNIT_ASSERT_EQUAL(aExpected, aActual);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
 
 }
diff --git a/writerperfect/qa/unit/data/writer/epubexport/hello.fodt b/writerperfect/qa/unit/data/writer/epubexport/hello.fodt
new file mode 100644
index 000000000000..b245e9d7abce
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/hello.fodt
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document office:mimetype="application/vnd.oasis.opendocument.text" office:version="1.2" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">
+  <office:body>
+    <office:text>
+      <text:p><text:span>Hello world!</text:span></text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/writerperfect/source/writer/EPUBPackage.cxx b/writerperfect/source/writer/EPUBPackage.cxx
index 3a33dedac3eb..0e34400171da 100644
--- a/writerperfect/source/writer/EPUBPackage.cxx
+++ b/writerperfect/source/writer/EPUBPackage.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/embed/XTransactedObject.hpp>
 #include <com/sun/star/io/XSeekable.hpp>
 #include <com/sun/star/xml/sax/Writer.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
 
 #include <comphelper/storagehelper.hxx>
 #include <unotools/mediadescriptor.hxx>
@@ -39,6 +40,10 @@ EPUBPackage::EPUBPackage(const uno::Reference<uno::XComponentContext> &xContext,
     mxOutputStream->writeBytes(aData);
     uno::Reference<embed::XTransactedObject> xTransactedObject(mxOutputStream, uno::UNO_QUERY);
     xTransactedObject->commit();
+
+    // MIME type must be uncompressed.
+    uno::Reference<beans::XPropertySet> xPropertySet(mxOutputStream, uno::UNO_QUERY);
+    xPropertySet->setPropertyValue("Compressed", uno::makeAny(false));
     mxOutputStream.clear();
 }
 


More information about the Libreoffice-commits mailing list