[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 16 22:08:18 UTC 2020


 sw/qa/extras/htmlexport/htmlexport.cxx |   42 ++++++++++++++++++++++++++++-----
 sw/source/filter/html/htmlatr.cxx      |    3 +-
 2 files changed, 38 insertions(+), 7 deletions(-)

New commits:
commit a8a7975db21578c3f6e3ace96323df867a1c6161
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Nov 7 17:17:35 2019 +0100
Commit:     Gülşah Köse <gulsah.kose at collabora.com>
CommitDate: Wed Jun 17 00:07:46 2020 +0200

    sw XHTML export: <blockquote> can't have character children
    
    Fixes the following reqif-xhtml validation error:
    
    ERROR at 214: [XSD] cvc-complex-type.2.3: Element 'reqif-xhtml:blockquote' cannot have character [children], because the type's content type is element-only.
    
    But this is probably useful in the general xhtml case as well.
    
    [ Also add a way to not load a document when we want to cover "store"
    behavior in a test. ]
    
    Change-Id: I88795271475863b9560ac1cb99636c507746f1e9
    Reviewed-on: https://gerrit.libreoffice.org/82239
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96484
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Gülşah Köse <gulsah.kose at collabora.com>

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index f5a4650cea64..707f668df727 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -41,11 +41,11 @@ public:
      * Wraps a reqif-xhtml fragment into an XHTML file, so an XML parser can
      * parse it.
      */
-    void wrapFragment(SvMemoryStream& rStream)
+    static void wrapFragment(const utl::TempFile& rTempFile, SvMemoryStream& rStream)
     {
         rStream.WriteCharPtr(
             "<reqif-xhtml:html xmlns:reqif-xhtml=\"http://www.w3.org/1999/xhtml\">\n");
-        SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
+        SvFileStream aFileStream(rTempFile.GetURL(), StreamMode::READ);
         rStream.WriteStream(aFileStream);
         rStream.WriteCharPtr("</reqif-xhtml:html>\n");
         rStream.Seek(0);
@@ -105,6 +105,11 @@ private:
 
 #define DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, nullptr, HtmlExportTest)
 
+/// HTML export of the sw doc model tests.
+class SwHtmlDomExportTest : public SwModelTestBase, public HtmlTestTools
+{
+};
+
 DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testFdo81276, "fdo81276.html")
 {
     uno::Reference<container::XNameAccess> xPageStyles(getStyles("PageStyles"));
@@ -571,7 +576,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOle2, "reqif-ole2.xhtml")
     {
         // Check that the replacement graphic is exported at RTF level.
         SvMemoryStream aStream;
-        wrapFragment(aStream);
+        wrapFragment(maTempFile, aStream);
         xmlDocPtr pDoc = parseXmlStream(&aStream);
         CPPUNIT_ASSERT(pDoc);
         // Get the path of the RTF data.
@@ -634,7 +639,7 @@ DECLARE_HTMLEXPORT_TEST(testTransparentImage, "transparent-image.odt")
 DECLARE_HTMLEXPORT_TEST(testTransparentImageReqIf, "transparent-image.odt")
 {
     SvMemoryStream aStream;
-    wrapFragment(aStream);
+    wrapFragment(maTempFile, aStream);
     xmlDocPtr pDoc = parseXmlStream(&aStream);
     CPPUNIT_ASSERT(pDoc);
 
@@ -651,7 +656,7 @@ DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, "reqif-ole-nodata.odt")
 {
     // This failed, io::IOException was thrown during the filter() call.
     SvMemoryStream aStream;
-    wrapFragment(aStream);
+    wrapFragment(maTempFile, aStream);
     xmlDocPtr pDoc = parseXmlStream(&aStream);
     CPPUNIT_ASSERT(pDoc);
 
@@ -666,7 +671,7 @@ DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, "reqif-ole-nodata.odt")
 DECLARE_HTMLEXPORT_TEST(testNoLangReqIf, "reqif-no-lang.odt")
 {
     SvMemoryStream aStream;
-    wrapFragment(aStream);
+    wrapFragment(maTempFile, aStream);
     xmlDocPtr pDoc = parseXmlStream(&aStream);
     CPPUNIT_ASSERT(pDoc);
 
@@ -690,6 +695,31 @@ DECLARE_HTMLEXPORT_TEST(testFieldShade, "field-shade.odt")
     assertXPath(pDoc, "/html/body/p[2]/span/span", 0);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteReqIf)
+{
+    // Build a document model that uses the Quotations paragraph style.
+    loadURL("private:factory/swriter", nullptr);
+    uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), uno::UNO_QUERY);
+    xParagraph->setPropertyValue("ParaStyleName", uno::makeAny(OUString("Quotations")));
+
+    // Export it.
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("HTML (StarWriter)");
+    aMediaDescriptor["FilterOptions"] <<= OUString("xhtmlns=reqif-xhtml");
+    xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+    SvMemoryStream aStream;
+    HtmlExportTest::wrapFragment(maTempFile, aStream);
+    xmlDocPtr pDoc = parseXmlStream(&aStream);
+    CPPUNIT_ASSERT(pDoc);
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 1
+    // - Actual  : 0
+    // i.e. <blackquote> had character (direct) children, which is invalid xhtml.
+    assertXPath(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:blockquote/reqif-xhtml:p", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx
index 02f8f31ec26b..d44411c67dee 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -803,8 +803,9 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat,
     // for BLOCKQUOTE, ADDRESS and DD we output another paragrah token, if
     // - no styles are written and
     // - a lower spacing or a paragraph alignment exists
+    // Also, XHTML does not allow character children in this context.
     OString aToken = rInfo.aToken;
-    if( !rHWrt.m_bCfgOutStyles && rInfo.bParaPossible && !bPara &&
+    if( (!rHWrt.m_bCfgOutStyles || rHWrt.mbXHTML) && rInfo.bParaPossible && !bPara &&
         (bHasParSpace || pAdjItem) )
     {
         HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHWrt.GetNamespace() + rInfo.aToken );


More information about the Libreoffice-commits mailing list