sw/qa/extras/ooxmlexport/data/tdf146171.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport12.cxx        |    4 ++--
 sw/qa/extras/ooxmlexport/ooxmlexport16.cxx        |   18 ++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   11 ++++++++++-
 4 files changed, 30 insertions(+), 3 deletions(-)

New commits:
commit 2c51746997478ad5d0e7cc64aa6489769c473d43
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Mar 2 16:41:04 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Mar 2 21:20:29 2022 +0100

    tdf#146171 DOCX: fix loss of change tracking, if no date
    
    was specified, or it was specified as zero date (e.g. in
    a LO DOCX export).
    
    DateTime attribute w:date is optional in w:ins/w:del
    according to the OOXML standard. Not specified w:date was
    imported as invalid zero date "0-00-00T00:00:00Z" resulting
    loss of change tracking data completely during an ODF
    roundtrip.
    
    Import this invalid zero date as Epoch time to avoid losing
    change tracking data.
    
    Change-Id: If8442db9aa5e41c470827545c36c64f598887101
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130885
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf146171.docx 
b/sw/qa/extras/ooxmlexport/data/tdf146171.docx
new file mode 100644
index 000000000000..bdd534527a99
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf146171.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
index 775f7f4154ab..c568f7228a7b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx
@@ -1223,9 +1223,9 @@ DECLARE_OOXMLEXPORT_TEST(testTdf145720, "tdf104797.docx")
         assertXPath(pXmlDoc, 
"/w:document/w:body/w:p[2]/w:moveTo/w:moveToRangeStart", "author",
                     u"Tekijä");
         assertXPath(pXmlDoc, 
"/w:document/w:body/w:p[1]/w:moveFrom/w:moveFromRangeStart", "date",
-                    "0-00-00T00:00:00Z");
+                    "1970-01-01T00:00:00Z");
         assertXPath(pXmlDoc, 
"/w:document/w:body/w:p[2]/w:moveTo/w:moveToRangeStart", "date",
-                    "0-00-00T00:00:00Z");
+                    "1970-01-01T00:00:00Z");
     }
 }
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index 7fe132b69e68..543a7580bd79 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -645,6 +645,24 @@ CPPUNIT_TEST_FIXTURE(Test, testTextframeHyperlink)
     assertXPath(pXmlDoc, "//w:pict/v:rect", "href", 
"https://libreoffice.org/";);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf146171_invalid_change_date)
+{
+    load(mpTestDocumentPath, "tdf146171.docx");
+    // false alarm? during ODF roundtrip:
+    // 'Error: "1970-01-01" does not satisfy the "dateTime" type'
+    // disable and check only the conversion of the invalid (zeroed) change 
date
+    // reload("writer8", "tdf146171.odt");
+    reload("Office Open XML Text", "tdf146171.docx");
+
+    xmlDocUniquePtr pXmlDoc = parseExport();
+    // This was 0
+    assertXPath(pXmlDoc, "//w:ins", 4);
+    // This was 0
+    assertXPath(pXmlDoc, "//w:del", 1);
+    // This was 0000-00-00T00:00:00Z, resulting loss of change tracking during 
ODF roundtrip
+    assertXPath(pXmlDoc, "//w:del", "date", "1970-01-01T00:00:00Z");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf139580, "tdf139580.odt")
 {
     // Without the fix in place, this test would have crashed at export time
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4460b9caa13b..2475da8baa5b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3145,7 +3145,16 @@ void 
DomainMapper_Impl::CreateRedline(uno::Reference<text::XTextRange> const& xR
         pRedlineProperties[0].Name = getPropertyName( PROP_REDLINE_AUTHOR );
         pRedlineProperties[0].Value <<= pRedline->m_sAuthor;
         pRedlineProperties[1].Name = getPropertyName( PROP_REDLINE_DATE_TIME );
-        pRedlineProperties[1].Value <<= 
ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate );
+        util::DateTime aDateTime = 
ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate );
+        // tdf#146171 import not specified w:date (or specified as zero date 
"0-00-00")
+        // as Epoch time to avoid of losing change tracking data during ODF 
roundtrip
+        if ( aDateTime.Year == 0 && aDateTime.Month == 0 && aDateTime.Day == 0 
)
+        {
+            aDateTime.Year = 1970;
+            aDateTime.Month = 1;
+            aDateTime.Day = 1;
+        }
+        pRedlineProperties[1].Value <<= aDateTime;
         pRedlineProperties[2].Name = getPropertyName( 
PROP_REDLINE_REVERT_PROPERTIES );
         pRedlineProperties[2].Value <<= pRedline->m_aRevertProperties;
         pRedlineProperties[3].Name = "RedlineMoved";

Reply via email to