diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-03-30 11:20:12 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-12-13 14:33:17 +0100 |
commit | 4ec8fbc0dafae3068fb45e2ec26405bc59b43ace (patch) | |
tree | d3890ab7cffdc358919436bfb109b10fa21f652d /sw | |
parent | 0e36d99bb8fb04c88b15845b17ee705ed60d66b7 (diff) |
sw: fix crash in SwAttrSet::CopyToModify()
Regression from commit 938a4d6624a78f3e272b3c4c07f314cb0c6db723
(tdf#128375 sw: fix copying RES_PARATR_LIST_AUTOFMT to different SwDoc,
2019-11-01), the problem is that we may get an autofmt pool item which
is set, but its style handle is empty. Assume that this is the same case
as having no autofmt at all.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132301
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
(cherry picked from commit ddfafd9b67e6e61c144b29ac73bbafb413ddf03b)
Change-Id: I87494fd04687d31201b4ec712cb0fb1ec7362b46
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143888
Tested-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/CppunitTest_sw_core_attr.mk | 74 | ||||
-rw-r--r-- | sw/Module_sw.mk | 1 | ||||
-rw-r--r-- | sw/qa/core/attr/attr.cxx | 86 | ||||
-rw-r--r-- | sw/qa/core/attr/data/attr-set.docx | bin | 0 -> 11582 bytes | |||
-rw-r--r-- | sw/source/core/attr/swatrset.cxx | 3 |
5 files changed, 163 insertions, 1 deletions
diff --git a/sw/CppunitTest_sw_core_attr.mk b/sw/CppunitTest_sw_core_attr.mk new file mode 100644 index 000000000000..91ae9c8b44e6 --- /dev/null +++ b/sw/CppunitTest_sw_core_attr.mk @@ -0,0 +1,74 @@ +# -*- 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,sw_core_attr)) + +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_attr)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_attr, \ + sw/qa/core/attr/attr \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sw_core_attr, \ + comphelper \ + cppu \ + cppuhelper \ + editeng \ + sal \ + sfx \ + svl \ + svx \ + svxcore \ + sw \ + test \ + unotest \ + utl \ + vcl \ + tl \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sw_core_attr,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_set_include,sw_core_attr,\ + -I$(SRCDIR)/sw/inc \ + -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ + -I$(SRCDIR)/sw/qa/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sw_core_attr,\ + udkapi \ + offapi \ + oovbaapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sw_core_attr)) +$(eval $(call gb_CppunitTest_use_vcl,sw_core_attr)) + +$(eval $(call gb_CppunitTest_use_rdb,sw_core_attr,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_attr,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sw_core_attr)) + +$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_attr, \ + modules/swriter \ +)) + +$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_attr)) + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index 0a2f2876736e..943748922397 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -115,6 +115,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_core_unocore \ CppunitTest_sw_core_crsr \ CppunitTest_sw_core_edit \ + CppunitTest_sw_core_attr \ )) ifneq ($(DISABLE_GUI),TRUE) diff --git a/sw/qa/core/attr/attr.cxx b/sw/qa/core/attr/attr.cxx new file mode 100644 index 000000000000..a406a91f1f4b --- /dev/null +++ b/sw/qa/core/attr/attr.cxx @@ -0,0 +1,86 @@ +/* -*- 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 <swmodeltestbase.hxx> + +#include <docsh.hxx> +#include <swdtflvr.hxx> +#include <swmodule.hxx> + +#include <com/sun/star/frame/DispatchHelper.hpp> + +namespace +{ +char const DATA_DIRECTORY[] = "/sw/qa/core/attr/data/"; + +/// Covers sw/source/core/attr/ fixes. +class Test : public SwModelTestBase +{ +public: + SwDoc* createDoc(const char* pName = nullptr); +}; + +SwDoc* Test::createDoc(const char* pName) +{ + if (!pName) + loadURL("private:factory/swriter", nullptr); + else + load(DATA_DIRECTORY, pName); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + return pTextDoc->GetDocShell()->GetDoc(); +} + +static void dispatchCommand(const uno::Reference<lang::XComponent>& xComponent, + const OUString& rCommand, + const uno::Sequence<beans::PropertyValue>& rPropertyValues) +{ + uno::Reference<frame::XController> xController + = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController(); + CPPUNIT_ASSERT(xController.is()); + uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xFrame.is()); + + uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext(); + uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext)); + CPPUNIT_ASSERT(xDispatchHelper.is()); + + xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues); +} + +CPPUNIT_TEST_FIXTURE(Test, testSwAttrSet) +{ + // Given a document with track changes and the whole document is selected: + SwDoc* pDoc = createDoc("attr-set.docx"); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + dispatchCommand(mxComponent, ".uno:Cut", {}); + dispatchCommand(mxComponent, ".uno:SelectAll", {}); + rtl::Reference<SwTransferable> xTransferable(new SwTransferable(*pWrtShell)); + SwModule* pMod = SW_MOD(); + SwTransferable* pOldTransferable = pMod->m_pXSelection; + pMod->m_pXSelection = xTransferable.get(); + + // When getting the plain text version of the selection: + datatransfer::DataFlavor aFlavor; + aFlavor.MimeType = "text/plain;charset=utf-16"; + aFlavor.DataType = cppu::UnoType<OUString>::get(); + uno::Any aData = xTransferable->getTransferData(aFlavor); + + // Then make sure we get data without crashing: + CPPUNIT_ASSERT(aData.hasValue()); + pMod->m_pXSelection = pOldTransferable; +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/attr/data/attr-set.docx b/sw/qa/core/attr/data/attr-set.docx Binary files differnew file mode 100644 index 000000000000..0cb8508aa2a4 --- /dev/null +++ b/sw/qa/core/attr/data/attr-set.docx diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx index 7cd6303ecef1..55835c5d1c30 100644 --- a/sw/source/core/attr/swatrset.cxx +++ b/sw/source/core/attr/swatrset.cxx @@ -398,7 +398,8 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const } if (pSrcDoc != pDstDoc && - SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem)) + SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem) + && static_cast<SwFormatAutoFormat const*>(pItem)->GetStyleHandle()) { SfxItemSet const& rAutoStyle(*static_cast<SwFormatAutoFormat const&>(*pItem).GetStyleHandle()); std::shared_ptr<SfxItemSet> const pNewSet( |