diff options
author | László Németh <nemeth@numbertext.org> | 2022-03-02 16:41:04 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2022-03-02 21:20:29 +0100 |
commit | 2c51746997478ad5d0e7cc64aa6489769c473d43 (patch) | |
tree | 92401fe8d577bbdf93dc09be6af782ad74bed3eb | |
parent | 89101372c892d2ec3cfa8008101cbfb56ac1cf99 (diff) |
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 <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf146171.docx | bin | 0 -> 11710 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport12.cxx | 4 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 18 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 11 |
4 files changed, 30 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf146171.docx b/sw/qa/extras/ooxmlexport/data/tdf146171.docx Binary files differnew file mode 100644 index 000000000000..bdd534527a99 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf146171.docx 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"; |