From da0e4cdc4f6bf8e0e88a4dd0e00afdf68e59a883 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 21 Nov 2024 13:57:14 +0500 Subject: tdf#163974: ignore nested footnotes on ODF import That is a valid, but unsupported, markup, that is explicitly mentioned in ODF 1.4 part 3 "Schema" sect. 6.3.4 "": Note: The schema allows for the inclusion of elements as a descendant of a child of the element. While this may be reasonable for note types, it is not reasonable for footnotes and endnotes. Conforming consumers need not support notes inside notes. (The "reasonable for note types" is obviously an editorial error from the time when ODF 1.1 text "reasonable for some future note types" was reviewed for ODF 1.2.) As the ODF also specifies, that a conforming consumer "need not interpret the semantics of all elements, attributes and attribute values" (ibid., sect. 2.4 "Consumer"), it is OK to silently drop this data, just as done for other similar cases. Change-Id: I0a417981087ebf225565628f14409661058d100d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176906 Reviewed-by: Mike Kaganski Tested-by: Jenkins (cherry picked from commit 512ef23224987e3107e66241db3b42934e15a561) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176919 Reviewed-by: Michael Stahl --- xmloff/source/text/XMLFootnoteImportContext.cxx | 14 +++++++++++++- xmloff/source/text/XMLFootnoteImportContext.hxx | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'xmloff') 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 #include #include #include @@ -102,7 +103,16 @@ void XMLFootnoteImportContext::startFastElement( // save old cursor and install new one xOldCursor = rHelper.GetCursor(); Reference 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; -- cgit