sw/qa/extras/odfexport/data/tdf107292.odt |binary sw/qa/extras/odfexport/odfexport.cxx | 11 +++++++++++ sw/source/filter/xml/XMLRedlineImportHelper.cxx | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+)
New commits: commit 76784f2dbf6d8641cfb6bf5d24e37521d6c806df Author: László Németh <nem...@numbertext.org> AuthorDate: Wed Dec 8 10:11:06 2021 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Dec 8 12:40:51 2021 +0100 tdf#107292: ODT import: fix order of deletions at same position Tracked deletions at the same position were loaded in reverse order, resulting broken text content. Note: FODT format is not applicable for the unit test document, because it's not affected by the problem. Change-Id: Id13f8d23ae5964cbf82095a3d1ce2f6c9fdd59e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126529 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/qa/extras/odfexport/data/tdf107292.odt b/sw/qa/extras/odfexport/data/tdf107292.odt new file mode 100644 index 000000000000..f35da387f964 Binary files /dev/null and b/sw/qa/extras/odfexport/data/tdf107292.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index f7ed88cd04a9..d3fe6465b4d4 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -561,6 +561,17 @@ DECLARE_ODFEXPORT_TEST(testredlineTextFrame, "redlineTextFrame.odt") CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); } +DECLARE_ODFEXPORT_TEST(testTdf107292, "tdf107292.odt") +{ + // tracked deletions at the same position were loaded in reverse order + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + // Without this fix in place, this test would have failed with + // - Expected: Lorem ipsum dolor sit... + // - Actual : dolor ipsumLorem sit... + CPPUNIT_ASSERT_EQUAL(OUString("Lorem ipsum dolor sit..."), getParagraph(1)->getString()); +} + DECLARE_ODFEXPORT_TEST(testTdf140437, "tdf140437.odt") { // Without the fix in place, the document would have failed to load diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx index 5e289bb7648f..2edaf23cf847 100644 --- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx +++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx @@ -653,6 +653,22 @@ void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo) new SwRangeRedline( pRedlineData, *aPaM.GetPoint(), !pRedlineInfo->bMergeLastParagraph ); + // tdf#107292 fix order of delete redlines at the same position by removing + // the already inserted redlines temporarily and inserting them back in reverse + // order after inserting pRedline + std::vector<const SwRangeRedline*> aSwapRedlines; + if ( RedlineType::Delete == pRedlineInfo->eType ) + { + SwRedlineTable::size_type n = 0; + while ( const SwRangeRedline* pRedline2 = + pDoc->getIDocumentRedlineAccess().GetRedline( *pRedline->Start(), &n ) ) + { + SwRedlineTable& aRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable(); + aSwapRedlines.push_back(pRedline2); + aRedlineTable.Remove(n); + } + } + // set mark if( aPaM.HasMark() ) { @@ -674,6 +690,11 @@ void XMLRedlineImportHelper::InsertIntoDocument(RedlineInfo* pRedlineInfo) // set redline mode (without doing the associated book-keeping) pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern(RedlineFlags::On); pDoc->getIDocumentRedlineAccess().AppendRedline(pRedline, false); + + // restore the correct order of the delete redlines at the same position + for (auto i = aSwapRedlines.rbegin(); i != aSwapRedlines.rend(); ++i) + pDoc->getIDocumentRedlineAccess().AppendRedline(const_cast<SwRangeRedline*>(*i), false); + pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern(RedlineFlags::NONE); } }