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
This commit is contained in:
Miklos Vajna 2019-11-11 14:08:14 +01:00
parent ec2a820551
commit b280c02d58
5 changed files with 122 additions and 10 deletions

View File

@ -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:

View File

@ -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:

Binary file not shown.

65
oox/qa/unit/mathml.cxx Normal file
View File

@ -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: */

View File

@ -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);
}
}
}