sw/qa/extras/ooxmlexport/data/tdf168988_grabbagDatePicker.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport25.cxx                     |   14 +++++++
 sw/source/filter/ww8/docxattributeoutput.cxx                   |   18 
++--------
 3 files changed, 18 insertions(+), 14 deletions(-)

New commits:
commit 05a2bdfc892f903cfa316f23562bccd179125f4d
Author:     Justin Luth <[email protected]>
AuthorDate: Wed Feb 11 16:25:49 2026 -0500
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Feb 12 16:52:56 2026 +0100

    tdf#168988 docx export: ensure valid ISO8601 FormDate fullDate
    
    Without this fix, datePickers with invalid content
    were dumping the content into the fullDate element on export,
    which caused MS Word to report the file as corrupt.
    
    datePickers inside tables are imported
    as fields by LO, not as a date content control.
    (I believe this can be changed by an advanced config setting.)
    
    So, if invalid content was loaded into ODF_FORMDATE_CURRENTDATE
    (which is fine - it SHOULD be displayed)
    it was then being round-tripped as both content
    AND as the fullDate element.
    Just round-trip non-date strings as content.
    
    make CppunitTest_sw_ooxmlexport25 \
        CPPUNIT_TEST_NAME=testTdf168988_grabbagDatePicker
    
    Change-Id: I1275de94f1da5f0bb9a319c52ea8a4c67e9564ae
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199218
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199278
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf168988_grabbagDatePicker.docx 
b/sw/qa/extras/ooxmlexport/data/tdf168988_grabbagDatePicker.docx
new file mode 100644
index 000000000000..ac8c29eb943a
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf168988_grabbagDatePicker.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
index 4649e916b556..5b855c4db3a3 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
@@ -181,6 +181,20 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf165359_SdtWithDrawing)
     assertXPath(pXmlDoc, "//w:sdtPr/w:text", 0);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf168988_grabbagDatePicker)
+{
+    createSwDoc("tdf168988_grabbagDatePicker.docx");
+
+    save(TestFilter::DOCX);
+    xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
+    assertXPath(pXmlDoc, "//w:sdt", 1); // only one sdt
+    assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date", 1); // it is a date content 
control
+    // there is no valid date, so fullDate must not be provided (or MS Word 
says 'corrupt file')
+    assertXPathNoAttribute(pXmlDoc, "//w:sdt/w:sdtPr/w:date", "fullDate");
+    assertXPathContent(pXmlDoc, "//w:sdt/w:sdtContent/w:r/w:t",
+                       u"                                     2012./2013.");
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTdf170389_manyTabstops)
 {
     createSwDoc("tdf170389_manyTabstops.odt");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 79dc73574236..3992dfdc1a75 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2950,20 +2950,10 @@ void DocxAttributeOutput::StartField_Impl( const 
SwTextNode* pNode, sal_Int32 nP
         FieldMarkParamsHelper params(rFieldmark);
 
         OUString sFullDate;
-        OUString sCurrentDate;
-        params.extractParam( ODF_FORMDATE_CURRENTDATE, sCurrentDate );
-        if(!sCurrentDate.isEmpty())
-        {
-            sFullDate = sCurrentDate + "T00:00:00Z";
-        }
-        else
-        {
-            std::pair<bool, double> aResult = rFieldmark.GetCurrentDate();
-            if(aResult.first)
-            {
-                sFullDate = 
rFieldmark.GetDateInStandardDateFormat(aResult.second) + "T00:00:00Z";
-            }
-        }
+        std::pair<bool, double> aResult = rFieldmark.GetCurrentDate();
+        // fullDate must be a valid ISO8601 date string or MS Word reports the 
file as corrupt
+        if (aResult.first) // bFoundValidDate is true
+            sFullDate = rFieldmark.GetDateInStandardDateFormat(aResult.second) 
+ "T00:00:00Z";
 
         OUString sDateFormat;
         params.extractParam( ODF_FORMDATE_DATEFORMAT, sDateFormat );

Reply via email to