sw/qa/extras/uiwriter/data/TC-table-del-add.docx |binary
 sw/qa/extras/uiwriter/uiwriter4.cxx              |   19 +++++++++++++++++
 sw/source/core/doc/docredln.cxx                  |   25 -----------------------
 3 files changed, 19 insertions(+), 25 deletions(-)

New commits:
commit 6a9cf64ea7509aac258f290cc1f204fd1ce1f974
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Sat Dec 11 14:24:24 2021 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Dec 13 19:34:33 2021 +0100

    tdf#146208 sw DOCX: fix crash at Redo of tracked table changes
    
    Importing DOCX tables with tracked row deletion and insertion,
    accepting them, Undo, and accepting them again (or Redo)
    crashed LibreOffice, related to the missing Undo support
    of deletions in SwExtraRedlineTable.
    
    SwTableRowRedline is not used for DOCX export since
    commit dbc2bdffbec9b3f7eba485652cdd43634458b5a6
    "tdf#145091 DOCX: don't export obsolete table row change data",
    so it's possible to switch off deletion of row changes
    in SwExtraRedlineTable to fix crashing, keeping SwTableRowRedline
    only to fix the round-trip of the original row change Date
    temporarily.
    
    Change-Id: I6ac571656e45c4299a07a63646bb28d6d1fcd081
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126662
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/data/TC-table-del-add.docx 
b/sw/qa/extras/uiwriter/data/TC-table-del-add.docx
new file mode 100644
index 000000000000..841e63f0d12b
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/TC-table-del-add.docx 
differ
diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx 
b/sw/qa/extras/uiwriter/uiwriter4.cxx
index 40db48e65e92..bddc76755920 100644
--- a/sw/qa/extras/uiwriter/uiwriter4.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter4.cxx
@@ -200,6 +200,7 @@ public:
     void testTdf104440();
     void testTdf104425();
     void testTdf104814();
+    void testTableRedlineRedoCrash();
     void testTdf66405();
     void testTdf35021_tabOverMarginDemo();
     void testTdf106701_tabOverMarginAutotab();
@@ -322,6 +323,7 @@ public:
     CPPUNIT_TEST(testTdf104440);
     CPPUNIT_TEST(testTdf104425);
     CPPUNIT_TEST(testTdf104814);
+    CPPUNIT_TEST(testTableRedlineRedoCrash);
     CPPUNIT_TEST(testTdf66405);
     CPPUNIT_TEST(testTdf35021_tabOverMarginDemo);
     CPPUNIT_TEST(testTdf106701_tabOverMarginAutotab);
@@ -1659,6 +1661,23 @@ void SwUiWriterTest4::testTdf104814()
         pEditShell->AcceptRedline(0);
 }
 
+// crash at redo of accepting table change tracking imported from DOCX
+void SwUiWriterTest4::testTableRedlineRedoCrash()
+{
+    SwDoc* const pDoc(createSwDoc(DATA_DIRECTORY, "TC-table-del-add.docx"));
+    sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
+
+    // accept all redlines, Undo and accept all redlines again
+
+    IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
+    rIDRA.AcceptAllRedline(/*bAccept=*/true);
+
+    rUndoManager.Undo();
+
+    // without the fix, it crashes
+    rIDRA.AcceptAllRedline(true);
+}
+
 void SwUiWriterTest4::testTdf66405()
 {
     // Imported formula should have zero margins
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 96f3742ce8f1..0d0b7fa621e2 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -172,31 +172,6 @@ bool SwExtraRedlineTable::DeleteAllTableRedlines( SwDoc& 
rDoc, const SwTable& rT
                 }
             }
         }
-        else
-        {
-            const SwTableRowRedline* pTableRowRedline = dynamic_cast<const 
SwTableRowRedline*>(pExtraRedline);
-            if (pTableRowRedline)
-            {
-                const SwTableLine *pRedTabLine = 
&pTableRowRedline->GetTableLine();
-                const SwTableBoxes &rRedTabBoxes = pRedTabLine->GetTabBoxes();
-                const SwTable& rRedTable = 
rRedTabBoxes[0]->GetSttNd()->FindTableNode()->GetTable();
-                if ( &rRedTable == &rTable )
-                {
-                    // Redline for this table
-                    const SwRedlineData& aRedlineData = 
pTableRowRedline->GetRedlineData();
-                    const RedlineType nRedlineType = aRedlineData.GetType();
-
-                    // Check if this redline object type should be deleted
-                    if (RedlineType::Any == nRedlineTypeToDelete || 
nRedlineTypeToDelete == nRedlineType)
-
-                    {
-                        DeleteAndDestroy( nCurRedlinePos );
-                        bChg = true;
-                        continue; // don't increment position after delete
-                    }
-                }
-            }
-        }
         ++nCurRedlinePos;
     }
 

Reply via email to