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

New commits:
commit 2eed35dcb721ebce08460b0e72a770336baf806d
Author:     Justin Luth <[email protected]>
AuthorDate: Wed Jan 14 15:16:10 2026 -0500
Commit:     Justin Luth <[email protected]>
CommitDate: Sat Jan 17 02:06:57 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/+/197300
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <[email protected]>

diff --git a/sw/qa/extras/layout/layout4.cxx b/sw/qa/extras/layout/layout4.cxx
index b1e3897acd12..37a32c3ab533 100644
--- a/sw/qa/extras/layout/layout4.cxx
+++ b/sw/qa/extras/layout/layout4.cxx
@@ -1120,6 +1120,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 2079d2ddff33..23f9914fb5d2 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -4890,6 +4890,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