comphelper/source/misc/asyncnotification.cxx | 1 sw/qa/extras/uiwriter/uiwriter.cxx | 30 ++++++++++++++++++--------- sw/source/core/unocore/unocrsrhelper.cxx | 10 +++++++++ 3 files changed, 32 insertions(+), 9 deletions(-)
New commits: commit a41f1b3a19a33194d56e1720d3ae46229db0f5c6 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Thu Apr 14 18:33:21 2022 +0200 Commit: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> CommitDate: Tue Apr 19 13:00:47 2022 +0200 sw: check if cursor position is valid before inserting file SwXTextCursor::insertDocumentFromURL() must not insert the file inside of an input field. If the CH_TXT_ATR_INPUTFIELD* become separated to different text nodes, things are going to break. Change-Id: Ia170e63f6c6d8a8fdd18f0b91e2b333e660ed924 diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index d11cf4e2d3f8..64cf555a95aa 100755 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -38,15 +38,7 @@ #include <unocrsr.hxx> #include <unocrsrhelper.hxx> #include <unotbl.hxx> -#include <IMark.hxx> -#include <IDocumentMarkAccess.hxx> -#include <IDocumentSettingAccess.hxx> -#include <pagedesc.hxx> -#include <postithelper.hxx> -#include <PostItMgr.hxx> -#include <AnnotationWin.hxx> -#include "com/sun/star/text/XDefaultNumberingProvider.hpp" -#include "com/sun/star/awt/FontUnderline.hpp" +#include <com/sun/star/document/XDocumentInsertable.hpp> #include <svx/svdpage.hxx> #include <svx/svdview.hxx> @@ -129,6 +121,7 @@ public: void testDOCXAutoTextGallery(); void testWatermarkDOCX(); void testTdf67238(); + void testInsertFileInInputFieldException(); void testFdo75110(); void testFdo75898(); void testFdo74981(); @@ -278,6 +271,7 @@ public: CPPUNIT_TEST(testDOCXAutoTextGallery); CPPUNIT_TEST(testWatermarkDOCX); CPPUNIT_TEST(testTdf67238); + CPPUNIT_TEST(testInsertFileInInputFieldException); CPPUNIT_TEST(testFdo75110); CPPUNIT_TEST(testFdo75898); CPPUNIT_TEST(testFdo74981); @@ -559,6 +553,24 @@ void SwUiWriterTest::testBookmarkCopy() } } +SwUiWriterTest::testInsertFileInInputFieldException +{ + createSwDoc(); + uno::Reference<text::XTextDocument> const xTextDoc(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> const xBody(xTextDoc->getText()); + uno::Reference<lang::XMultiServiceFactory> const xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextCursor> const xCursor(xBody->createTextCursor()); + uno::Reference<document::XDocumentInsertable> const xInsertable(xCursor, uno::UNO_QUERY); + uno::Reference<text::XTextContent> const xContent( + xFactory->createInstance("com.sun.star.text.textfield.Input"), uno::UNO_QUERY); + xBody->insertTextContent(xCursor, xContent, false); + xCursor->goLeft(1, false); + // try to insert some random file + OUString const url(m_directories.getURLFromSrc(DATA_DIRECTORY) + "fdo75110.odt"); + // inserting even asserts in debug builds - document model goes invalid with input field split across 2 nodes + CPPUNIT_ASSERT_THROW(xInsertable->insertDocumentFromURL(url, {}), uno::RuntimeException); +} + void SwUiWriterTest::testTdf67238() { //create a new writer document diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 547598423ab7..4dc38b347e8f 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -955,6 +955,16 @@ void resetCursorPropertyValue(const SfxItemPropertySimpleEntry& rEntry, SwPaM& r void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL, const uno::Sequence< beans::PropertyValue >& rOptions) { + if (SwTextNode const*const pTextNode = pUnoCursor->GetPoint()->nNode.GetNode().GetTextNode()) + { + // TODO: check meta field here too in case it ever grows a 2nd char + if (pTextNode->GetTextAttrAt(pUnoCursor->GetPoint()->nContent.GetIndex(), + RES_TXTATR_INPUTFIELD, SwTextNode::PARENT)) + { + throw uno::RuntimeException("cannot insert file inside input field"); + } + } + std::unique_ptr<SfxMedium> pMed; SwDoc* pDoc = pUnoCursor->GetDoc(); SwDocShell* pDocSh = pDoc->GetDocShell(); commit c19adeab9860d961fe74bce583ac5b77cc7cbf51 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Thu Jun 15 15:37:57 2017 +0200 Commit: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> CommitDate: Tue Apr 19 13:00:47 2022 +0200 Missing include Change-Id: I3345d989dc279f080d26c60888daa67154b3c0e9 (cherry picked from commit 1d0890bb241d7ef3d52057e3d2715277d081b0e5) diff --git a/comphelper/source/misc/asyncnotification.cxx b/comphelper/source/misc/asyncnotification.cxx index 942ba308e263..bb53b096a5d7 100644 --- a/comphelper/source/misc/asyncnotification.cxx +++ b/comphelper/source/misc/asyncnotification.cxx @@ -25,6 +25,7 @@ #include <cassert> #include <deque> +#include <stdexcept> #include <vector> #include <functional> #include <algorithm>