sw/qa/extras/layout/layout4.cxx                 |    7 +++++++
 sw/source/writerfilter/dmapper/DomainMapper.cxx |    2 ++
 2 files changed, 9 insertions(+)

New commits:
commit 99d670991cb9257cb6286018fa7ff10ebb1c2ed0
Author:     Justin Luth <[email protected]>
AuthorDate: Wed Jan 14 15:16:10 2026 -0500
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Jan 19 09:40:45 2026 +0100

    tdf#170322 writerfilter: import fields into richText, not plainText
    
    MS Word complains that documents are corrupt
    if a <w:text/> w:sdt (plainText content control)
    contains a field.
    
    This failing was brought to our attention by 24.2.2
    commit 13a11632014ccc27199667c6a1e313f8ff616d6d
        "tdf#159259: make sure to set FieldStartRange in sdt helper"
    
    One 'field' that is NOT adversely affected is a hyperlink,
    but I don't see how to identify that, since
      m_pImpl->GetTopFieldContext()->GetFieldId()
    was optional-has_no_value at this point
    as seen with ooxmlexport3's glossaryWithEmail.docx.
    
    But I can't really imagine a big problem
    turning a plainText into a richText by accident
    for the cases where it is not strictly necessary.
    In fact, I expect that ALL unknown types
    ought to be richText instead of plainText,
    since by definition not specifying anything is a richText control.
    
    make CppunitTest_sw_layoutwriter4 CPPUNIT_TEST_NAME=testTdf159259
    except that this was not writing an ending </w:sdt>...
    
    Change-Id: Ib393f8eaf024d332be3f3603f72ef644fb5fe8c7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197483
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    Reviewed-by: Justin Luth <[email protected]>

diff --git a/sw/qa/extras/layout/layout4.cxx b/sw/qa/extras/layout/layout4.cxx
index 82c91f914447..9cb8be16e24c 100644
--- a/sw/qa/extras/layout/layout4.cxx
+++ b/sw/qa/extras/layout/layout4.cxx
@@ -1087,6 +1087,13 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, testTdf159259)
 
     CPPUNIT_ASSERT_EQUAL(paraRight, flyRight); // The fly is right-aligned
     CPPUNIT_ASSERT_EQUAL(paraHeight, flyHeight);
+
+    // tdf#170322: MS Word considers the document corrupt if a plainText 
control contains a field
+    // save(TestFilter::DOCX);
+    // xmlDocUniquePtr pXmlDocument = parseExport(u"word/document.xml"_ustr);
+    // assertXPath(pXmlDocument, "//w:sdt/w:sdtPr", 1);
+    // // the sdtPr must be a richText control, not plainText
+    // assertXPath(pXmlDocument, "//w:sdt/w:sdtPr/w:text", 0);
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, testLargeTopParaMarginAfterHiddenSection)
diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper.cxx
index 8fa48d3ccf2e..14cbf84eed35 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -4705,6 +4705,8 @@ void DomainMapper::lcl_utext(const sal_Unicode *const 
data_, size_t len)
                         m_pImpl->m_pSdtHelper->createPlainTextControl();
                     else if (!m_pImpl->m_pSdtHelper->isFieldStartRangeSet())
                         
m_pImpl->m_pSdtHelper->setFieldStartRange(GetCurrentTextRange()->getEnd());
+                    // MS Word says plainText control containing a field is a 
corrupt file
+                    
m_pImpl->m_pSdtHelper->setControlType(SdtControlType::richText);
                 }
                 m_pImpl->AppendFieldCommand(sText);
             }

Reply via email to