sw/qa/extras/htmlexport/data/NestingInA1.fodt |   47 +++++++++++++++++
 sw/qa/extras/htmlexport/htmlexport.cxx        |   69 ++++++++++++++++++++++++++
 sw/source/filter/html/wrthtml.cxx             |   17 +++---
 3 files changed, 126 insertions(+), 7 deletions(-)

New commits:
commit 094fc93dfb5f9f6d441e63a8515c09d6165add00
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Aug 4 07:46:12 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Aug 4 10:59:48 2023 +0200

    tdf#156602: fix handling of nesting of tables in the document beginning
    
    The old code only accounted for a single table in the document start,
    finding the innermost table, and so ignoring any outer tables there.
    Do the same as for nesting sections: find the outermost one.
    
    Change-Id: Ide0e5bcf7c81e43fa5467da86e2e7e00a7076528
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155332
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/htmlexport/data/NestingInA1.fodt 
b/sw/qa/extras/htmlexport/data/NestingInA1.fodt
new file mode 100644
index 000000000000..439ef0a57d42
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/NestingInA1.fodt
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+  <office:text>
+   <table:table table:name="Outer">
+    <table:table-column table:number-columns-repeated="2"/>
+    <table:table-row>
+     <table:table-cell office:value-type="string">
+      <table:table table:name="Inner">
+       <table:table-column table:number-columns-repeated="2"/>
+       <table:table-row>
+        <table:table-cell office:value-type="string">
+         <text:p>Inner.A1</text:p>
+        </table:table-cell>
+        <table:table-cell office:value-type="string">
+         <text:p>Inner.B1</text:p>
+        </table:table-cell>
+       </table:table-row>
+       <table:table-row>
+        <table:table-cell office:value-type="string">
+         <text:p>Inner.A2</text:p>
+        </table:table-cell>
+        <table:table-cell office:value-type="string">
+         <text:p>Inner.B2</text:p>
+        </table:table-cell>
+       </table:table-row>
+      </table:table>
+      <text:p>Outer.A1</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string">
+      <text:p>Outer.B1</text:p>
+     </table:table-cell>
+    </table:table-row>
+    <table:table-row>
+     <table:table-cell office:value-type="string">
+      <text:p>Outer.A2</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string">
+      <text:p>Outer.B2</text:p>
+     </table:table-cell>
+    </table:table-row>
+   </table:table>
+   <text:p>Following text</text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index ab825a735fa7..becda28a832a 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2645,6 +2645,75 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testSingleOleExport)
     CPPUNIT_ASSERT_EQUAL(tools::Long(450), xReader->GetObjh());
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_Tdf156602)
+{
+    createSwDoc("NestingInA1.fodt");
+    ExportToReqif();
+
+    xmlDocUniquePtr pDoc = WrapReqifFromTempFile();
+
+    // The outer table must be kept in the document where the outer table is 
the first element,
+    // and its A1 starts with a nested table
+
+    // Only two sub-elements must be inside the div: an outer table and a 
trailing paragraph
+    assertXPathChildren(pDoc, "/reqif-xhtml:html/reqif-xhtml:div", 2);
+    // The outer table must have exactly two rows
+    assertXPath(pDoc, 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr", 2);
+    // First outer table cell must have two sub-elements: an inner table and a 
trailing paragraph
+    assertXPathChildren(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]",
+        2);
+    // The inner table must have exactly two rows
+    assertXPath(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/"
+        "reqif-xhtml:table/reqif-xhtml:tr",
+        2);
+    // Check all the elements' content
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/"
+        "reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/reqif-xhtml:p",
+        "Inner.A1");
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/"
+        "reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[2]/reqif-xhtml:p",
+        "Inner.B1");
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/"
+        "reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[1]/reqif-xhtml:p",
+        "Inner.A2");
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/"
+        "reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[2]/reqif-xhtml:p",
+        "Inner.B2");
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/"
+        "reqif-xhtml:p",
+        "Outer.A1");
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[2]/"
+        "reqif-xhtml:p",
+        "Outer.B1");
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[1]/"
+        "reqif-xhtml:p",
+        "Outer.A2");
+    assertXPathContent(
+        pDoc,
+        
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[2]/"
+        "reqif-xhtml:p",
+        "Outer.B2");
+    assertXPathContent(pDoc, 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "Following text");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/wrthtml.cxx 
b/sw/source/filter/html/wrthtml.cxx
index 97b2de547c7b..26b97e431027 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -496,17 +496,20 @@ ErrCode SwHTMLWriter::WriteStream()
 
     // respect table and section at document beginning
     {
-        SwTableNode * pTNd = m_pCurrentPam->GetPointNode().FindTableNode();
-        if( pTNd && m_bWriteAll )
+        if (m_bWriteAll)
         {
-            // start with table node !!
-            m_pCurrentPam->GetPoint()->Assign(*pTNd);
+            while (const SwStartNode* pTNd = 
m_pCurrentPam->GetPointNode().FindTableBoxStartNode())
+            {
+                // start with table node !!
+                m_pCurrentPam->GetPoint()->Assign(*pTNd->FindTableNode());
 
-            if( m_bWriteOnlyFirstTable )
-                m_pCurrentPam->GetMark()->Assign(*pTNd->EndOfSectionNode());
+                if (m_bWriteOnlyFirstTable)
+                    m_pCurrentPam->GetMark()->Assign(
+                        *m_pCurrentPam->GetPointNode().EndOfSectionNode());
+            }
         }
 
-        // first node (with can contain a page break)
+        // first node (which can contain a page break)
         m_pStartNdIdx = new SwNodeIndex( m_pCurrentPam->GetPoint()->GetNode() 
);
 
         SwSectionNode * pSNd = m_pCurrentPam->GetPointNode().FindSectionNode();

Reply via email to