summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/qa/extras/odfimport/data/nested_footnote.fodt11
-rw-r--r--sw/qa/extras/odfimport/odfimport.cxx15
-rw-r--r--xmloff/source/text/XMLFootnoteImportContext.cxx14
-rw-r--r--xmloff/source/text/XMLFootnoteImportContext.hxx1
4 files changed, 40 insertions, 1 deletions
diff --git a/sw/qa/extras/odfimport/data/nested_footnote.fodt b/sw/qa/extras/odfimport/data/nested_footnote.fodt
new file mode 100644
index 000000000000..812f4610926c
--- /dev/null
+++ b/sw/qa/extras/odfimport/data/nested_footnote.fodt
@@ -0,0 +1,11 @@
+<?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" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+ <office:text>
+ <text:p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.<text:note text:note-class="footnote"><text:note-citation>1</text:note-citation><text:note-body>
+ <text:p>Vestibulum consequat mi quis pretium semper.<text:note text:note-class="footnote"><text:note-citation>2</text:note-citation><text:note-body>
+ <text:p>Proin luctus orci ac neque venenatis, quis commodo dolor posuere.</text:p></text:note-body></text:note></text:p></text:note-body></text:note></text:p>
+ </office:text>
+ </office:body>
+</office:document> \ No newline at end of file
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index 2525075b3ee5..e4bfa18a442d 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -59,6 +59,7 @@
#include <docsh.hxx>
#include <unotxdoc.hxx>
#include <frmatr.hxx>
+#include <expfld.hxx>
#if defined(_WIN32)
#include <officecfg/Office/Common.hxx>
@@ -1639,6 +1640,20 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf162398)
SwTransferable::PasteFormat(*pWrtShell, aDataHelper, SotClipboardFormatId::HTML);
}
+CPPUNIT_TEST_FIXTURE(Test, testTdf163974)
+{
+ // A document with a footnote inside a footnote must load normally, ignoring unsupported markup.
+ // Without the fix, this would fail to load.
+ createSwDoc("nested_footnote.fodt");
+
+ SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+ CPPUNIT_ASSERT(pWrtShell->HasFootnotes());
+ SwSeqFieldList footnotes;
+ pWrtShell->GetSeqFootnoteList(footnotes);
+ // If we ever support the nested footnotes, this would naturally change
+ CPPUNIT_ASSERT_EQUAL(size_t(1), footnotes.Count());
+}
+
} // end of anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/text/XMLFootnoteImportContext.cxx b/xmloff/source/text/XMLFootnoteImportContext.cxx
index a73147ec09f1..fc9605bd8651 100644
--- a/xmloff/source/text/XMLFootnoteImportContext.cxx
+++ b/xmloff/source/text/XMLFootnoteImportContext.cxx
@@ -19,6 +19,7 @@
#include "XMLFootnoteImportContext.hxx"
+#include <comphelper/diagnose_ex.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <xmloff/xmlimp.hxx>
@@ -102,7 +103,16 @@ void XMLFootnoteImportContext::startFastElement(
// save old cursor and install new one
xOldCursor = rHelper.GetCursor();
Reference<XText> xText(xTextContent, UNO_QUERY);
- rHelper.SetCursor(xText->createTextCursor());
+ try
+ {
+ // May fail e.g. for a nested footnote, which is formally a valid ODF, but is not supported
+ rHelper.SetCursor(xText->createTextCursor());
+ }
+ catch (css::uno::RuntimeException&)
+ {
+ TOOLS_WARN_EXCEPTION("xmloff.text", "skipping the footnote: caught");
+ mbIsValid = false;
+ }
// remember old list item and block (#89891#) and reset them
// for the footnote
@@ -132,6 +142,8 @@ void XMLFootnoteImportContext::endFastElement(sal_Int32 )
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLFootnoteImportContext::createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
{
+ if (!mbIsValid)
+ return {};
SvXMLImportContextRef xContext;
switch(nElement)
diff --git a/xmloff/source/text/XMLFootnoteImportContext.hxx b/xmloff/source/text/XMLFootnoteImportContext.hxx
index d05b7b631c22..8321639bbd1a 100644
--- a/xmloff/source/text/XMLFootnoteImportContext.hxx
+++ b/xmloff/source/text/XMLFootnoteImportContext.hxx
@@ -42,6 +42,7 @@ class XMLFootnoteImportContext : public SvXMLImportContext
/// old list item and block (#89891#)
bool mbListContextPushed;
+ bool mbIsValid = true;
/// text import helper; holds current XTextCursor (and XText)
XMLTextImportHelper& rHelper;