sw/qa/extras/ooxmlimport/data/tdf168567.docx    |binary
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx       |   39 ++++++++++++++++++++++++
 sw/source/writerfilter/dmapper/DomainMapper.cxx |    3 +
 3 files changed, 42 insertions(+)

New commits:
commit eaef560633e0e2f83ba5188b24111db55a873741
Author:     Karthik Godha <[email protected]>
AuthorDate: Thu Oct 16 11:52:06 2025 +0530
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Oct 27 10:37:16 2025 +0100

    tdf#168567: Fix import of SDTs with empty content
    
    regression from commit 7c4dba1deffd81f647a4a3be7a79f68f3bf9f1
    
    SDTs(content controls) with empty paragraph content are not properly
    imported.
    
    Change-Id: I340a060f03b419b3352fad2a8fb5ac3af043be54
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192466
    Reviewed-by: Michael Stahl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    (cherry picked from commit 72a326b2899115860a87cfa55b82f745a76128da)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192952
    Tested-by: Jenkins
    (cherry picked from commit 2444243cab5f49fdec77de332491e9ae5c57b0f4)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192960
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/qa/extras/ooxmlimport/data/tdf168567.docx 
b/sw/qa/extras/ooxmlimport/data/tdf168567.docx
new file mode 100644
index 000000000000..43803f847408
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf168567.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 9e5daa6dab96..20735e1e14f1 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/style/BreakType.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
+#include <com/sun/star/table/XCellRange.hpp>
 
 #include <comphelper/propertysequence.hxx>
 #include <vcl/BitmapReadAccess.hxx>
@@ -1333,6 +1334,44 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf154370)
         CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, 
ePropertyState);
     }
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf168567)
+{
+    createSwDoc("tdf168567.docx");
+
+    // Access the first table in the doc
+    uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTablesSupplier->getTextTables(),
+                                                    uno::UNO_QUERY);
+    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
+    uno::Reference<table::XTableRows> xRows = xTable->getRows();
+    uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY);
+
+    sal_Int32 nLastRow = xRows->getCount() - 1;
+
+    // Check if all cells in the last row contain `Content Controls`(SDTs)
+    for (sal_Int32 col = 0; col < xTable->getColumns()->getCount(); col++)
+    {
+        uno::Reference<text::XText> xCell(xCellRange->getCellByPosition(col, 
nLastRow),
+                                          uno::UNO_QUERY);
+
+        uno::Reference<container::XEnumerationAccess> xParaAccess(xCell, 
uno::UNO_QUERY);
+        uno::Reference<container::XEnumeration> xParagraphs = 
xParaAccess->createEnumeration();
+
+        uno::Reference<container::XEnumerationAccess> 
xParagraph(xParagraphs->nextElement(),
+                                                                 
uno::UNO_QUERY);
+        uno::Reference<container::XEnumeration> xPortions = 
xParagraph->createEnumeration();
+
+        uno::Reference<beans::XPropertySet> 
xTextPortion(xPortions->nextElement(), uno::UNO_QUERY);
+
+        // Check if it's a content control
+        // Without the fix the last cell will result false
+        OUString aPortionType;
+        xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= 
aPortionType;
+        CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType);
+    }
+}
+
 // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in 
ooxmlEXPORT
 
 } // end of anonymous namespace
diff --git a/sw/source/writerfilter/dmapper/DomainMapper.cxx 
b/sw/source/writerfilter/dmapper/DomainMapper.cxx
index af80351723ef..12318a263f80 100644
--- a/sw/source/writerfilter/dmapper/DomainMapper.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapper.cxx
@@ -4621,6 +4621,9 @@ void DomainMapper::lcl_utext(const sal_Unicode *const 
data_, size_t len)
     {
         if (bNewLine)
         {
+            if (!m_pImpl->m_pSdtHelper->isFieldStartRangeSet())
+                
m_pImpl->m_pSdtHelper->setFieldStartRange(GetCurrentTextRange()->getEnd());
+
             m_pImpl->m_pSdtHelper->createPlainTextControl();
             finishParagraph();
             return;

Reply via email to