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 a0cfbcdba4aab6b4f73a62d99b977fad99fda01f
Author:     Justin Luth <[email protected]>
AuthorDate: Wed Feb 11 16:25:49 2026 -0500
Commit:     Miklos Vajna <[email protected]>
CommitDate: Thu Feb 12 13:41:26 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/+/199229
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Justin Luth <[email protected]>
    Reviewed-by: Miklos Vajna <[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 cdb4f5fdde89..06cbd300921d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
@@ -157,6 +157,20 @@ CPPUNIT_TEST_FIXTURE(Test, 
testTdf170516_drawingBeforePlainText)
     assertXPath(pXmlDoc, "//w:tc/w:p/w:r/mc:AlternateContent", 1); // and it 
is not inside the sdt
 }
 
+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 bc39dab918ea..6a9aa39fb36b 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2959,20 +2959,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