sw/qa/extras/ooxmlexport/data/content-control-grab-bag.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx               |   12 ++++++++++++
 writerfilter/source/dmapper/DomainMapper.cxx                |    3 ++-
 3 files changed, 14 insertions(+), 1 deletion(-)

New commits:
commit 5e73cdf0dd64c1d627377354575c86be90d910fb
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Aug 16 11:37:27 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Sep 23 08:54:19 2022 +0200

    crashtesting: fix DOCX export of forum-mso-de-99522.docx
    
    Export of this document to DOCX wrote not-well-formed XML output,
    resulting in an assertion failure in debug builds.
    
    writerfilter/ maps a selection of <w:sdt> tags to Writer content
    controls (a safe subset), and leaves the rest unchanged, which means we
    continue to map those to grab-bags. The trouble is that a combination of
    content controls and grab-bags leads to bad output on export, as we
    start the <w:sdt> element twice, but only close it once.
    
    Fix the problem by extending writerfilter/ code to not do any grab-bags
    for the richText type, we already did that in the past for dropDowns.
    
    In the long run, we should never do grab-bagging for any <w:sdt>
    elements that we map to Writer content controls.
    
    (cherry picked from commit 7ad44f3dd271a591529b048212c4391d8b38ed9d)
    
    Change-Id: I27a0b814efd667cc0477d8f492f7f956c938c854
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140431
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/content-control-grab-bag.docx 
b/sw/qa/extras/ooxmlexport/data/content-control-grab-bag.docx
new file mode 100644
index 000000000000..33c01f08fd25
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/content-control-grab-bag.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index 9cf424f8aa07..3747aa399a27 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -818,6 +818,18 @@ DECLARE_OOXMLEXPORT_TEST( testSdtDatePicker, 
"test_sdt_datepicker.docx" )
     CPPUNIT_ASSERT_EQUAL(OUString("008000"), sColor);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testContentControlGrabBag)
+{
+    // Given a document with a <w:sdt> tag:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"content-control-grab-bag.docx";
+    loadURL(aURL, nullptr);
+
+    // When exporting that document back to DOCX:
+    // Then make sure that completes without an assertion failure, which would 
mean not-well-formed
+    // output was produced:
+    save("Office Open XML Text", maTempFile);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf104823)
 {
     // Test how we can roundtrip sdt plain text with databindings support
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx 
b/writerfilter/source/dmapper/DomainMapper.cxx
index 26f564acbe4c..e79a46784dab 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3792,7 +3792,8 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, 
size_t len)
         else
         {
             uno::Sequence<beans::PropertyValue> aGrabBag = 
m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear();
-            if (m_pImpl->GetSdtStarts().empty() || 
m_pImpl->m_pSdtHelper->getControlType() != SdtControlType::dropDown)
+            if (m_pImpl->GetSdtStarts().empty()
+                || (m_pImpl->m_pSdtHelper->getControlType() != 
SdtControlType::dropDown && m_pImpl->m_pSdtHelper->getControlType() != 
SdtControlType::richText))
             {
                 
m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)->Insert(PROP_SDTPR,
                         uno::makeAny(aGrabBag), true, PARA_GRAB_BAG);

Reply via email to