sw/qa/extras/ooxmlexport/ooxmlexport21.cxx           |   28 ++++++++++++++-----
 sw/source/writerfilter/dmapper/DomainMapper.cxx      |    2 -
 sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx |    4 +-
 3 files changed, 24 insertions(+), 10 deletions(-)

New commits:
commit 44eda1f72b4d67b9627155741067d3e57a1f9747
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Sat Feb 8 20:00:38 2025 -0500
Commit:     Justin Luth <justin.l...@collabora.com>
CommitDate: Mon Feb 10 15:13:28 2025 +0100

    tdf#164876 tdf#165117 writerfilter: no dummy paragraphs in header
    
    The problem was that an extra CR was being added
    (often every round-trip) to headers that started with a table.
    
    This is a long-standing bug (see moz1211781-1.docx)
    that got more exposure recently from changes to
    7.6.6 (via 86ad08f9d25110e91e92a0badf6de75e785b3644)
    and 24.8.0 (via ef77086255821d61838a7e26fee9baadaca0b9e0)
    
    make CppunitTest_sw_ooxmlexport21 CPPUNIT_TEST_NAME=testTdf161631
    
    Change-Id: Idb6a0efda246fa064822f01a9ce097f686810b5c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181307
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 472a4f3cc179..91bf853c784c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -41,15 +41,29 @@ public:
     }
 };
 
-DECLARE_OOXMLEXPORT_TEST(testTdf161631, "tdf161631.docx")
+CPPUNIT_TEST_FIXTURE(Test, testTdf161631)
 {
-    CPPUNIT_ASSERT_EQUAL(1, getPages());
-    CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
+    auto verify = [this](bool bIsExport = false) {
+        CPPUNIT_ASSERT_EQUAL(1, getPages());
+        CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
+
+        // Without the fix in place, this test would have failed with
+        // - Expected : Some text
+        // - Actual:
+        CPPUNIT_ASSERT_EQUAL(u"Some text"_ustr, getParagraph(1)->getString());
+
+        if (bIsExport)
+        {
+            // tdf#164876 tdf#165117: don't add an empty paragraph every 
round-trip
+            xmlDocUniquePtr pXmlDoc1 = parseExport(u"word/footer2.xml"_ustr);
+            assertXPath(pXmlDoc1, "/w:ftr/w:p", 1);
+        }
+    };
 
-    // Without the fix in place, this test would have failed with
-    // - Expected: Some text
-    // - Actual  :
-    CPPUNIT_ASSERT_EQUAL(u"Some text"_ustr, getParagraph(1)->getString());
+    createSwDoc("tdf161631.docx");
+    verify();
+    saveAndReload(mpFilter);
+    verify(/*bIsExport*/ true);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf158597, "tdf158597.docx")
diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper.cxx
index 45a911196cca..c8ee000c01e2 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -1501,7 +1501,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, const 
PropertyMapPtr& rContext )
             if (m_pImpl->m_StreamStateStack.top().nTableDepth == 0
                 && m_pImpl->GetIsFirstParagraphInSection()
                     && !m_pImpl->GetIsDummyParaAddedForTableInSection() && 
!m_pImpl->GetIsTextFrameInserted()
-                    && !m_pImpl->GetIsPreviousParagraphFramed() && 
!IsInHeaderFooter())
+                    && !m_pImpl->GetIsPreviousParagraphFramed())
             {
                 m_pImpl->AddDummyParaForTableInSection();
             }
diff --git a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
index b7e6c0828b94..3ac573f160d8 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx
@@ -689,8 +689,8 @@ void DomainMapper_Impl::RemoveDummyParaForTableInSection()
 }
 void DomainMapper_Impl::AddDummyParaForTableInSection()
 {
-    // Shapes and textboxes can't have sections.
-    if (IsInShape() || m_StreamStateStack.top().bIsInTextBox)
+    // Shapes, headers, and textboxes can't have sections.
+    if (IsInShape() || IsInHeaderFooter() || 
m_StreamStateStack.top().bIsInTextBox)
         return;
 
     if (!m_aTextAppendStack.empty())

Reply via email to