[Libreoffice-commits] core.git: sw/qa sw/source

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 17 15:49:05 UTC 2020


 sw/qa/core/unocore/unocore.cxx      |   22 ++++++++++++++++++++++
 sw/source/core/unocore/unodraw.cxx  |    9 ++++++++-
 sw/source/core/unocore/unoframe.cxx |    9 ++++++++-
 3 files changed, 38 insertions(+), 2 deletions(-)

New commits:
commit ca2dfac3e790fb384e904502fe1ededd695001af
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Jul 15 16:44:37 2020 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Fri Jul 17 17:48:25 2020 +0200

    sw: fix crash when using anchor of at-paragraph fly ...
    
    ... to insert fieldmark; the problem is that the anchor doesn't have
    SwIndex so the resulting sw::mark::Fieldmark's positions won't have
    SwIndex either, so they aren't updated when its dummy chars are inserted
    in lcl_SetFieldMarks().
    
    Change-Id: Id6281f45aa1f1337f1ae599877f155b129389d81
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98852
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index 54faad3d233c..38a700463846 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -10,6 +10,7 @@
 #include <swmodeltestbase.hxx>
 
 #include <com/sun/star/text/XTextAppend.hpp>
+#include <com/sun/star/text/XTextFrame.hpp>
 
 #include <wrtsh.hxx>
 #include <unotextrange.hxx>
@@ -58,6 +59,27 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testTdf119081)
     CPPUNIT_ASSERT_EQUAL(OUString("x"), pWrtShell->GetCurrentShellCursor().GetText());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, flyAtParaAnchor)
+{
+    mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    uno::Reference<lang::XMultiServiceFactory> const xMSF(mxComponent, uno::UNO_QUERY_THROW);
+    uno::Reference<text::XTextDocument> const xTD(mxComponent, uno::UNO_QUERY_THROW);
+    uno::Reference<text::XTextFrame> const xTextFrame(
+        xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet> const xFrameProps(xTextFrame, uno::UNO_QUERY_THROW);
+    xFrameProps->setPropertyValue("AnchorType",
+                                  uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH));
+    auto const xText = xTD->getText();
+    auto const xTextCursor = xText->createTextCursor();
+    CPPUNIT_ASSERT(xTextCursor.is());
+    xText->insertTextContent(xTextCursor, xTextFrame, false);
+    auto const xAnchor = xTextFrame->getAnchor();
+    uno::Reference<text::XTextContent> const xFieldmark(
+        xMSF->createInstance("com.sun.star.text.Fieldmark"), uno::UNO_QUERY_THROW);
+    // this crashed because the anchor didn't have SwIndex
+    xText->insertTextContent(xAnchor, xFieldmark, false);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 5e3ec6b23d37..d21756c65720 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -2068,7 +2068,14 @@ uno::Reference< text::XTextRange >  SwXShape::getAnchor()
             (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum()))
         {
             const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor());
-            aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+            if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA)
+            {   // ensure that SwXTextRange has SwIndex
+                aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.nNode), nullptr);
+            }
+            else
+            {
+                aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+            }
         }
     }
     else
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index dcb6d0ede363..c277d1179789 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2641,7 +2641,14 @@ uno::Reference< text::XTextRange >  SwXFrame::getAnchor()
         (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum()))
     {
         const SwPosition &rPos = *(rAnchor.GetContentAnchor());
-        aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+        if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PARA)
+        {   // ensure that SwXTextRange has SwIndex
+            aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), SwPosition(rPos.nNode), nullptr);
+        }
+        else
+        {
+            aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr);
+        }
     }
 
     return aRef;


More information about the Libreoffice-commits mailing list