summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-11-11 14:08:14 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-11-11 15:09:07 +0100
commitb280c02d584ad403417db0e8840f8ae6de245883 (patch)
tree80119208af0894bc3a03673049fd6bb3bebc6cd2 /oox
parentec2a8205519bd546fe75c1b98bc1d8add8f2f2ec (diff)
Related: tdf#117658 PPTX import: ignore math text outside <m:t>
This way a pretty-printed bug document doesn't assert on import with: soffice.bin: /home/vmiklos/git/libreoffice/master/oox/source/mathml/importutils.cxx:335: void oox::formulaimport::XmlStreamBuilder::appendCharacters(const rtl::OUString&): Assertion `!tags.empty()' failed. Change-Id: Icf8b11f3c56076b1ad2dddad196260ee87540020 Reviewed-on: https://gerrit.libreoffice.org/82437 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'oox')
-rw-r--r--oox/CppunitTest_oox_mathml.mk44
-rw-r--r--oox/Module_oox.mk1
-rw-r--r--oox/qa/unit/data/import-characters.pptxbin0 -> 33620 bytes
-rw-r--r--oox/qa/unit/mathml.cxx65
-rw-r--r--oox/source/mathml/import.cxx22
5 files changed, 122 insertions, 10 deletions
diff --git a/oox/CppunitTest_oox_mathml.mk b/oox/CppunitTest_oox_mathml.mk
new file mode 100644
index 000000000000..e358a9666fc3
--- /dev/null
+++ b/oox/CppunitTest_oox_mathml.mk
@@ -0,0 +1,44 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,oox_mathml))
+
+$(eval $(call gb_CppunitTest_use_externals,oox_mathml,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,oox_mathml, \
+ oox/qa/unit/mathml \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,oox_mathml, \
+ comphelper \
+ cppu \
+ oox \
+ sal \
+ test \
+ unotest \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,oox_mathml))
+
+$(eval $(call gb_CppunitTest_use_ure,oox_mathml))
+$(eval $(call gb_CppunitTest_use_vcl,oox_mathml))
+
+$(eval $(call gb_CppunitTest_use_rdb,oox_mathml,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,oox_mathml,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,oox_mathml))
+
+# vim: set noet sw=4 ts=4:
diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk
index 1f906231e981..636f9f6ece99 100644
--- a/oox/Module_oox.mk
+++ b/oox/Module_oox.mk
@@ -25,6 +25,7 @@ $(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_vba_compression \
CppunitTest_oox_vba_encryption \
CppunitTest_oox_crypto \
+ CppunitTest_oox_mathml \
))
# vim: set noet sw=4 ts=4:
diff --git a/oox/qa/unit/data/import-characters.pptx b/oox/qa/unit/data/import-characters.pptx
new file mode 100644
index 000000000000..29338023641c
--- /dev/null
+++ b/oox/qa/unit/data/import-characters.pptx
Binary files differ
diff --git a/oox/qa/unit/mathml.cxx b/oox/qa/unit/mathml.cxx
new file mode 100644
index 000000000000..632fc566ddb7
--- /dev/null
+++ b/oox/qa/unit/mathml.cxx
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+
+#include <comphelper/embeddedobjectcontainer.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/propertyvalue.hxx>
+#include <comphelper/scopeguard.hxx>
+#include <comphelper/storagehelper.hxx>
+
+using namespace ::com::sun::star;
+
+/// oox mathml tests.
+class OoxMathmlTest : public test::BootstrapFixture, public unotest::MacrosTest
+{
+private:
+ uno::Reference<uno::XComponentContext> mxComponentContext;
+ uno::Reference<lang::XComponent> mxComponent;
+
+public:
+ void setUp() override;
+ void tearDown() override;
+ uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
+};
+
+void OoxMathmlTest::setUp()
+{
+ test::BootstrapFixture::setUp();
+
+ mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
+ mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void OoxMathmlTest::tearDown()
+{
+ if (mxComponent.is())
+ mxComponent->dispose();
+
+ test::BootstrapFixture::tearDown();
+}
+
+char const DATA_DIRECTORY[] = "/oox/qa/unit/data/";
+
+CPPUNIT_TEST_FIXTURE(OoxMathmlTest, testImportCharacters)
+{
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "import-characters.pptx";
+ // Without the accompanying fix in place, this failed with an assertion failure on import.
+ getComponent() = loadFromDesktop(aURL);
+ CPPUNIT_ASSERT(getComponent().is());
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/mathml/import.cxx b/oox/source/mathml/import.cxx
index 5a02f8906955..ec338c451638 100644
--- a/oox/source/mathml/import.cxx
+++ b/oox/source/mathml/import.cxx
@@ -32,7 +32,7 @@ class LazyMathBufferingContext : public core::ContextHandler
{
private:
XmlStreamBuilder & m_rBuilder;
- long m_Counter;
+ std::vector<sal_Int32> m_OpenElements;
public:
LazyMathBufferingContext(core::ContextHandler const& rParent,
@@ -51,7 +51,6 @@ LazyMathBufferingContext::LazyMathBufferingContext(
core::ContextHandler const& rParent, drawingml::TextParagraph & rPara)
: core::ContextHandler(rParent)
, m_rBuilder(rPara.GetMathXml())
- , m_Counter(0)
{
}
@@ -59,22 +58,22 @@ void SAL_CALL LazyMathBufferingContext::startFastElement(
sal_Int32 const nElement,
uno::Reference<xml::sax::XFastAttributeList> const& xAttrs)
{
- if (0 < m_Counter) // ignore a14:m
+ if (0 < m_OpenElements.size()) // ignore a14:m
{ // ignore outer oMathPara
- if (1 != m_Counter || OOX_TOKEN(officeMath, oMathPara) != nElement)
+ if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
{
m_rBuilder.appendOpeningTag(nElement, xAttrs);
}
}
- ++m_Counter;
+ m_OpenElements.push_back(nElement);
}
void SAL_CALL LazyMathBufferingContext::endFastElement(sal_Int32 const nElement)
{
- --m_Counter;
- if (0 < m_Counter) // ignore a14:m
+ m_OpenElements.pop_back();
+ if (0 < m_OpenElements.size()) // ignore a14:m
{ // ignore outer oMathPara
- if (1 != m_Counter || OOX_TOKEN(officeMath, oMathPara) != nElement)
+ if (1 != m_OpenElements.size() || OOX_TOKEN(officeMath, oMathPara) != nElement)
{
m_rBuilder.appendClosingTag(nElement);
}
@@ -90,9 +89,12 @@ LazyMathBufferingContext::createFastChildContext(sal_Int32 const,
void SAL_CALL LazyMathBufferingContext::characters(OUString const& rChars)
{
- if (0 < m_Counter) // ignore a14:m
+ if (0 < m_OpenElements.size()) // ignore a14:m
{
- m_rBuilder.appendCharacters(rChars);
+ if (m_OpenElements.back() == OOX_TOKEN(officeMath, t))
+ {
+ m_rBuilder.appendCharacters(rChars);
+ }
}
}