sw/qa/extras/ooxmlexport/data/tdf138093B.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport19.cxx    |   37 ++++++++++++++++++++++++++
 sw/source/writerfilter/dmapper/SdtHelper.cxx  |    3 +-
 3 files changed, 39 insertions(+), 1 deletion(-)

New commits:
commit 3974c4748b9a2bcd054e0b9f9e3d42bdca45bef2
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Tue Jul 23 20:57:37 2024 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed Jul 24 13:52:00 2024 +0200

    tdf#138093 tdf#131722 docx import: sdt lost first date character #2
    
    While GetIsDummyParaAddedForTableInSection() is true
    for the entire section, it should only be used
    against GetIsFirstParagraphInSection()
    where the dummy para exists.
    
    make CppunitTest_sw_ooxmlexport19 CPPUNIT_TEST_NAME=testTdf138093B
    
    Change-Id: I457c0aa25eb7bd086c5c15bd889d9cd89c51db95
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170921
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/data/tdf138093B.docx 
b/sw/qa/extras/ooxmlexport/data/tdf138093B.docx
new file mode 100644
index 000000000000..f6f770a7160e
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf138093B.docx 
differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
index 8080bd448a55..dc2a291234c3 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
@@ -977,6 +977,43 @@ DECLARE_OOXMLEXPORT_TEST(testTdf138093, "tdf138093.docx")
     }
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf138093B)
+{
+    loadAndReload("tdf138093B.docx");
+
+    xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
+    assertXPath(pXmlDoc, "//w:sdt"_ostr, 3);
+    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(1), 
uno::UNO_QUERY);
+    uno::Reference<table::XCell> xCell = xTable->getCellByName(u"A1"_ustr);
+    uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParagraphs = 
xParagraphsAccess->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);
+
+    OUString aPortionType;
+    xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType;
+    CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType);
+
+    uno::Reference<text::XTextContent> xContentControl;
+    xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl;
+    uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+    bool bDate{};
+    xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate;
+    CPPUNIT_ASSERT(bDate);
+    uno::Reference<container::XEnumerationAccess> 
xContentControlEnumAccess(xContentControl,
+                                                                            
uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xContentControlEnum
+        = xContentControlEnumAccess->createEnumeration();
+    uno::Reference<text::XTextRange> 
xTextPortionRange(xContentControlEnum->nextElement(),
+                                                       uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(u"2019"_ustr, xTextPortionRange->getString());
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf131722, "tdf131722.docx")
 {
     if (isExported())
diff --git a/sw/source/writerfilter/dmapper/SdtHelper.cxx 
b/sw/source/writerfilter/dmapper/SdtHelper.cxx
index 7687843e7ae3..6f72f3cbab9c 100644
--- a/sw/source/writerfilter/dmapper/SdtHelper.cxx
+++ b/sw/source/writerfilter/dmapper/SdtHelper.cxx
@@ -459,7 +459,8 @@ void SdtHelper::createDateContentControl()
         // Modified to XOR relationship and adding dummy paragraph conditions
         bool bIsInTable = (m_rDM_Impl.hasTableManager() && 
m_rDM_Impl.getTableManager().isInTable())
                               != (0 < 
m_rDM_Impl.m_StreamStateStack.top().nTableDepth)
-                          && m_rDM_Impl.GetIsDummyParaAddedForTableInSection();
+                          && m_rDM_Impl.GetIsDummyParaAddedForTableInSection()
+                          && m_rDM_Impl.GetIsFirstParagraphInSection();
         if (bIsInTable)
             xCrsr->goRight(1, false);
         xCrsr->gotoEnd(true);

Reply via email to