sw/qa/extras/ooxmlexport/data/tdf148361.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |   16 ++++++++++++++++
 writerfilter/source/dmapper/SdtHelper.cxx    |   20 ++++++++++++++------
 writerfilter/source/dmapper/SdtHelper.hxx    |    3 +++
 4 files changed, 33 insertions(+), 6 deletions(-)

New commits:
commit 2d1bd913d9f896d55c03dd509eb11c81667c5436
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Mon Apr 4 18:05:18 2022 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Apr 6 09:34:49 2022 +0200

    tdf#148361: docx sdt: cleanup databinding data after inserting
    
    Databinding data is used only for current sdt block. It should
    be clean up after usage to avoid impact on next sdt blocks.
    
    Change-Id: I53f47dd655ed027d40eb518784dcae69813e612f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132524
    Tested-by: Jenkins
    Tested-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-by: Vasily Melenchuk <vasily.melenc...@cib.de>
    (cherry picked from commit fafadd7aee8c384af210008f693b5007a9f5ea48)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132595
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf148361.docx 
b/sw/qa/extras/ooxmlexport/data/tdf148361.docx
new file mode 100644
index 000000000000..ecf9a5f0087c
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf148361.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 370989a9d6b7..51f0d9fb9345 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -143,6 +143,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123642_BookmarkAtDocEnd, 
"tdf123642.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("Bookmark1"), getXPath(pXmlDoc, 
"/w:document/w:body/w:p[2]/w:bookmarkStart[1]", "name"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf148361, "tdf148361.docx")
+{
+    // Refresh fields and ensure cross-reference to numbered para is okay
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xFieldsAccess(xTextFieldsSupplier->getTextFields());
+
+    uno::Reference<container::XEnumeration> 
xFields(xFieldsAccess->createEnumeration());
+    CPPUNIT_ASSERT(xFields->hasMoreElements());
+
+    uno::Reference<text::XTextField> xTextField1(xFields->nextElement(), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("itadmin"), 
xTextField1->getPresentation(false));
+
+    uno::Reference<text::XTextField> xTextField2(xFields->nextElement(), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("[Type text]"), 
xTextField2->getPresentation(false));
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf142407, "tdf142407.docx")
 {
     uno::Reference<container::XNameAccess> xPageStyles = 
getStyles("PageStyles");
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx 
b/writerfilter/source/dmapper/SdtHelper.cxx
index 576d63d430c6..f4b02fab4d02 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -264,8 +264,7 @@ void SdtHelper::createDropDownControl()
     }
 
     // clean up
-    m_aDropDownItems.clear();
-    setControlType(SdtControlType::unknown);
+    clear();
 }
 
 void SdtHelper::createPlainTextControl()
@@ -296,8 +295,7 @@ void SdtHelper::createPlainTextControl()
                                    uno::makeAny(getInteropGrabBagAndClear()));
 
     // clean up
-    m_aDropDownItems.clear();
-    setControlType(SdtControlType::unknown);
+    clear();
 }
 
 void SdtHelper::createDateContentControl()
@@ -372,11 +370,11 @@ void SdtHelper::createDateContentControl()
                                                     uno::UNO_QUERY);
     xRefreshable->refresh();
 
-    setControlType(SdtControlType::unknown);
-
     // Store all unused sdt parameters from grabbag
     xNameCont->insertByName(UNO_NAME_MISC_OBJ_INTEROPGRABBAG,
                             uno::makeAny(getInteropGrabBagAndClear()));
+
+    clear();
 }
 
 void SdtHelper::createControlShape(awt::Size aSize,
@@ -423,6 +421,16 @@ bool SdtHelper::containedInInteropGrabBag(const OUString& 
rValueName)
         [&rValueName](const beans::PropertyValue& i) { return i.Name == 
rValueName; });
 }
 
+void SdtHelper::clear()
+{
+    m_aDropDownItems.clear();
+    setControlType(SdtControlType::unknown);
+    m_sDataBindingPrefixMapping.clear();
+    m_sDataBindingXPath.clear();
+    m_sDataBindingStoreItemID.clear();
+    m_aGrabBag.clear();
+}
+
 } // namespace writerfilter::dmapper
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx 
b/writerfilter/source/dmapper/SdtHelper.hxx
index e58d73168d79..d9a6115a1251 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -102,6 +102,9 @@ class SdtHelper final : public virtual SvRefBase
 
     void loadPropertiesXMLs();
 
+    /// Clear all collected attributes for futher reuse
+    void clear();
+
 public:
     explicit SdtHelper(DomainMapper_Impl& rDM_Impl,
                        css::uno::Reference<css::uno::XComponentContext> const& 
xContext);

Reply via email to