diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2022-04-14 18:33:21 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-04-19 12:57:57 +0200 |
commit | 42c6dfa1662603793cf6e2c5be99a8a8ed0acaa1 (patch) | |
tree | 18e5a76b76558e7e595db032985577752235db2f /sw | |
parent | b12727e15a82216f709ccb6e37a9029d60ad4831 (diff) |
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
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133028
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/unocore/unocrsrhelper.cxx | 10 |
2 files changed, 29 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index b4b7a9eac36d..8934ee1617ea 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -9,6 +9,7 @@ #include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/document/XDocumentInsertable.hpp> #include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <com/sun/star/i18n/TextConversionOption.hpp> #include <swmodeltestbase.hxx> @@ -262,6 +263,24 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testBookmarkCopy) } } +CPPUNIT_TEST_FIXTURE(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); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf67238) { //create a new writer document diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index e4f18b7a3b17..f75e95f30722 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -1025,6 +1025,16 @@ void resetCursorPropertyValue(const SfxItemPropertyMapEntry& rEntry, SwPaM& rPam 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& rDoc = pUnoCursor->GetDoc(); SwDocShell* pDocSh = rDoc.GetDocShell(); |