summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-04-09 16:40:01 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-04-09 18:37:44 +0200
commitce98bef935dccd79735615a9299b2aa7a1ab0b94 (patch)
treea4671733f355a92fc8ef3b20d488544df1fca229 /sw/qa
parent28eb086f5d256a1febd7b0f38f9cd77fac574031 (diff)
sw style copy: fix crash when handling a conditional paragraphy style
- "Text body" is normally a conditional style for a full-blown, default SwDoc - SwTransferable::GetData() creates a temporary, stripped down SwDoc, which has a "Text body" style, but it's not conditional - SwDoc::CopyFormatArr() assumes that in case the target already has a style with a given name, then either both the source and destination styles are conditional, or neither - in practice this only causes a crash if the style is customized, as we skip default styles, probably that's why this was not noticed so far The Online case invokes this as part of lok::Document::getSelectionType(), so it was enough to set the paragraph style to Text body and then select some of that text (with a suitable document) to hit this. Based on a patch from Michael Meeks, thanks for that. Change-Id: Ic3c27ec582ae1745469042856254313cbc996ee0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113877 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/tiledrendering/data/cond-coll-copy.odtbin0 -> 7351 bytes
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx26
2 files changed, 26 insertions, 0 deletions
diff --git a/sw/qa/extras/tiledrendering/data/cond-coll-copy.odt b/sw/qa/extras/tiledrendering/data/cond-coll-copy.odt
new file mode 100644
index 000000000000..8fa15f177eb7
--- /dev/null
+++ b/sw/qa/extras/tiledrendering/data/cond-coll-copy.odt
Binary files differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 54dd09b7d191..b5d8000c967f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -18,6 +18,7 @@
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
+#include <com/sun/star/datatransfer/XTransferable2.hpp>
#include <test/helper/transferable.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
@@ -45,6 +46,7 @@
#include <tools/json_writer.hxx>
#include <unotools/mediadescriptor.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/propertyvalue.hxx>
#include <drawdoc.hxx>
#include <ndtxt.hxx>
@@ -153,6 +155,7 @@ public:
void testBulletDeleteInvalidation();
void testBulletNoNumInvalidation();
void testBulletMultiDeleteInvalidation();
+ void testCondCollCopy();
CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback);
@@ -231,6 +234,7 @@ public:
CPPUNIT_TEST(testBulletDeleteInvalidation);
CPPUNIT_TEST(testBulletNoNumInvalidation);
CPPUNIT_TEST(testBulletMultiDeleteInvalidation);
+ CPPUNIT_TEST(testCondCollCopy);
CPPUNIT_TEST_SUITE_END();
private:
@@ -3070,6 +3074,28 @@ void SwTiledRenderingTest::testBulletMultiDeleteInvalidation()
CPPUNIT_ASSERT(!aFirstTextRect.IsOver(m_aInvalidations));
}
+void SwTiledRenderingTest::testCondCollCopy()
+{
+ // Given a document with a custom Text Body cond style:
+ SwXTextDocument* pXTextDocument = createDoc("cond-coll-copy.odt");
+ uno::Sequence<beans::PropertyValue> aPropertyValues
+ = { comphelper::makePropertyValue("Style", OUString("Text Body")),
+ comphelper::makePropertyValue("FamilyName", OUString("ParagraphStyles")) };
+ dispatchCommand(mxComponent, ".uno:StyleApply", aPropertyValues);
+ SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+ pWrtShell->SelAll();
+
+ // When getting the text selection, then make sure it doesn't crash:
+ uno::Reference<datatransfer::XTransferable2> xTransferable(pXTextDocument->getSelection(),
+ css::uno::UNO_QUERY);
+ datatransfer::DataFlavor aFlavor;
+ aFlavor.MimeType = "text/plain;charset=utf-16";
+ aFlavor.DataType = cppu::UnoType<OUString>::get();
+ CPPUNIT_ASSERT(xTransferable->isDataFlavorSupported(aFlavor));
+ // Without the accompanying fix in place, this test would have crashed.
+ xTransferable->getTransferData(aFlavor);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();