sw/qa/extras/ooxmlexport/data/tdf153804.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx        |   17 +++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    2 +-
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    2 +-
 4 files changed, 19 insertions(+), 2 deletions(-)

New commits:
commit 6d153fa9f5277b7324885e18b0a63e1af830b6c5
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Thu Jul 6 17:31:20 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Sun Jul 9 14:31:26 2023 +0200

    tdf#153804 DOCX import: fix lost footnotes in case of comments
    
    Incomplete handling of m_bIsFootnote had a conflict with
    XNote stream COMMENTS (i.e. not FOOTNOTES and ENDNOTES)
    since commit 96a856f87f16cca2e039c973c18d57c8b9dca362
    in DomainMapper::lcl_checkId(), resulting lost (order or
    content) of footnotes, when were comments in the document.
    
    Regression from commit 96a856f87f16cca2e039c973c18d57c8b9dca362
    "tdf#152206 DOCX import: fix mixed first footnote".
    
    Change-Id: I8d6901e8db1e183b959fecd350d6a263e79b5591
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154147
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf153804.docx 
b/sw/qa/extras/ooxmlexport/data/tdf153804.docx
new file mode 100644
index 000000000000..65a1fdfa8e17
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf153804.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 4718837981cc..67fba9e9b114 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -1352,6 +1352,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf153255)
     CPPUNIT_ASSERT_EQUAL( OUString("Footnote for pg4."), 
xFootnote4->getString().trim() );
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf153804)
+{
+    loadAndSave("tdf153804.docx");
+    xmlDocUniquePtr pXml = parseExport("word/footnotes.xml");
+    CPPUNIT_ASSERT(pXml);
+
+    uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xFootnotes = 
xFootnotesSupplier->getFootnotes();
+    uno::Reference<text::XTextRange> xLastFootnote(xFootnotes->getByIndex(1), 
uno::UNO_QUERY);
+    // This was empty
+    CPPUNIT_ASSERT_EQUAL( OUString("Footnote for pg 6"), 
xLastFootnote->getString().trim() );
+
+    uno::Reference<text::XTextRange> xLastButOne(xFootnotes->getByIndex(0), 
uno::UNO_QUERY);
+    // This was empty
+    CPPUNIT_ASSERT_EQUAL( OUString("Footnote for pg5"), 
xLastButOne->getString().trim() );
+}
+
 // skip test for macOS (missing fonts?)
 #if !defined(MACOSX)
 DECLARE_OOXMLEXPORT_TEST(testTdf146346, "tdf146346.docx")
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index e0820dfeccb2..1389b9cadc02 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4095,7 +4095,7 @@ void DomainMapper_Impl::PopFootOrEndnote()
     }
     m_aRedlines.pop();
     m_eSkipFootnoteState = SkipFootnoteSeparator::OFF;
-    m_bInFootOrEndnote = false;
+    m_bInFootOrEndnote = m_bInFootnote = false;
     m_pFootnoteContext = nullptr;
     m_bFirstParagraphInCell = m_bSaveFirstParagraphInCell;
 }
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index c6b38d6d62d0..b2fca78f45fe 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -863,7 +863,7 @@ public:
     void PushFootOrEndnote( bool bIsFootnote );
     void PopFootOrEndnote();
     bool IsInFootOrEndnote() const { return m_bInFootOrEndnote; }
-    bool IsInFootnote() const { return m_bInFootnote; }
+    bool IsInFootnote() const { return IsInFootOrEndnote() && m_bInFootnote; }
 
     void StartCustomFootnote(const PropertyMapPtr pContext);
     void EndCustomFootnote();

Reply via email to