[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - sw/qa sw/source

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 10 14:36:20 UTC 2020


 sw/qa/uitest/table/sheetToTable.py           |  107 +++++++++++++++++++++++++++
 sw/qa/uitest/writer_tests/data/hiddenRow.ods |binary
 sw/qa/uitest/writer_tests/data/tdf129083.odt |binary
 sw/source/uibase/dochdl/swdtflvr.cxx         |   15 +++
 4 files changed, 119 insertions(+), 3 deletions(-)

New commits:
commit c8d335f9bfa6a6fd0887171e2b51035dcbb42078
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Wed Dec 9 20:38:40 2020 +0100
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Thu Dec 10 15:35:46 2020 +0100

    tdf#138688 tdf#124646 sw: fix crash at pasting Calc data
    
    .. in a table before a numbered paragraph. Dispatcher
    calls of the workaround for tdf#124646 missed the temporary
    table in this case, selecting + copying nothing and after
    that trying to paste the same non-native Calc data again,
    resulting infinite recursion.
    
    Replacing FN_CHAR_LEFT with FN_LINE_UP solved the
    problem (FN_CHAR_LEFT selected the numbers of the
    numbered list instead of the temporary table).
    Fixing the fragile dispatcher calls, now we check
    the selection of the temporary table to avoid similar
    crashes.
    
    Unit tests are added for the fix, also for the
    original problem of tdf#124646 (avoid copying
    hidden rows from Calc, e.g. copying only visible
    result of a filtering).
    
    Regression from commit 0c3ac02d8a3c7ea50ae262daf134c28df5c8b343
    (tdf#124646 Don't paste hidden rows of Calc sheets into Writer tables).
    
    (Note: to check/show the fix of the crash manually, run the test with
    
    $ (cd sw && make -srj8 UITest_sw_table UITEST_TEST_NAME="sheetToTable.sheetToTable.test_tdf138688" SAL_USE_VCLPLUGIN=gen)
    
    adding
    
    import time
    time.sleep(5)
    
    to the called function of sheetToTable.py)
    
    Change-Id: I7b90af8219d6fd00b75d91f7c92fff5744373cc6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107508
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit 7720f8cf22718415adb3db2304916581f864f884)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107487
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/sw/qa/uitest/table/sheetToTable.py b/sw/qa/uitest/table/sheetToTable.py
new file mode 100644
index 000000000000..d14529d4af9e
--- /dev/null
+++ b/sw/qa/uitest/table/sheetToTable.py
@@ -0,0 +1,107 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
+from uitest.uihelper.common import select_pos
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import get_state_as_dict, type_text
+from uitest.uihelper.calc import enter_text_to_cell
+import org.libreoffice.unotest
+import pathlib
+
+def get_url_for_data_file(file_name):
+    return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+#Calc sheet to Writer table
+
+class sheetToTable(UITestCase):
+    def test_sheet_to_table_without_hidden_rows(self):
+        calc_doc = self.ui_test.load_file(get_url_for_data_file("hiddenRow.ods"))
+        xCalcDoc = self.xUITest.getTopFocusWindow()
+        self.xUITest.executeCommand(".uno:SelectAll")
+        self.xUITest.executeCommand(".uno:Copy")
+        gridwin = xCalcDoc.getChild("grid_window")
+        document = self.ui_test.get_component()
+        self.ui_test.close_doc()
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("tableToText.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+        self.xUITest.executeCommand(".uno:Paste")
+        #verify (don't copy hidden cells)
+        self.assertEqual(document.TextTables.getCount(), 1)
+        table = document.getTextTables()[0]
+        # This was 3 (copied hidden row)
+        self.assertEqual(len(table.getRows()), 2)
+        self.assertEqual(table.getCellByName("A1").getString(), "1")
+        # This was "2 (hidden)" (copied hidden row)
+        self.assertEqual(table.getCellByName("A2").getString(), "3")
+        self.ui_test.close_doc()
+
+    def test_tdf138688(self):
+        calc_doc = self.ui_test.load_file(get_url_for_data_file("hiddenRow.ods"))
+        xCalcDoc = self.xUITest.getTopFocusWindow()
+        self.xUITest.executeCommand(".uno:SelectAll")
+        self.xUITest.executeCommand(".uno:Copy")
+        gridwin = xCalcDoc.getChild("grid_window")
+        document = self.ui_test.get_component()
+        self.ui_test.close_doc()
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("tableToText.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        # set numbering in the paragraph after the table
+        self.xUITest.executeCommand(".uno:GoDown")
+        self.xUITest.executeCommand(".uno:GoDown")
+        self.xUITest.executeCommand(".uno:DefaultNumbering")
+        self.xUITest.executeCommand(".uno:GoUp")
+        self.xUITest.executeCommand(".uno:GoUp")
+
+        #verify (this was a freezing/crash)
+        self.xUITest.executeCommand(".uno:Paste")
+
+        #verify also tdf#124646 (don't copy hidden cells)
+        self.assertEqual(document.TextTables.getCount(), 1)
+        table = document.getTextTables()[0]
+        # This was 3 (copied hidden row)
+        self.assertEqual(len(table.getRows()), 2)
+        self.assertEqual(table.getCellByName("A1").getString(), "1")
+        # This was "2 (hidden)" (copied hidden row)
+        self.assertEqual(table.getCellByName("A2").getString(), "3")
+        self.ui_test.close_doc()
+
+    def test_tdf129083(self):
+        calc_doc = self.ui_test.create_doc_in_start_center("calc")
+
+        xCalcDoc = self.xUITest.getTopFocusWindow()
+        gridwin = xCalcDoc.getChild("grid_window")
+        document = self.ui_test.get_component()
+
+        enter_text_to_cell(gridwin, "A1", "Test 1")
+        enter_text_to_cell(gridwin, "A2", "Test 2")
+        enter_text_to_cell(gridwin, "A3", "Test 3")
+        enter_text_to_cell(gridwin, "A4", "Test 4")
+
+        gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
+
+        self.xUITest.executeCommand(".uno:Copy")
+
+        self.ui_test.close_doc()
+
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("tdf129083.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        self.xUITest.executeCommand(".uno:Paste")
+
+        self.assertEqual(document.TextTables.getCount(), 1)
+        table = document.getTextTables()[0]
+        self.assertEqual(len(table.getRows()), 4)
+        self.assertEqual(table.getCellByName("A1").getString(), "Test 1")
+        self.assertEqual(table.getCellByName("A2").getString(), "Test 2")
+        self.assertEqual(table.getCellByName("A3").getString(), "Test 3")
+        self.assertEqual(table.getCellByName("A4").getString(), "Test 4")
+        self.ui_test.close_doc()
diff --git a/sw/qa/uitest/writer_tests/data/hiddenRow.ods b/sw/qa/uitest/writer_tests/data/hiddenRow.ods
new file mode 100644
index 000000000000..8b5d98a182fb
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/hiddenRow.ods differ
diff --git a/sw/qa/uitest/writer_tests/data/tdf129083.odt b/sw/qa/uitest/writer_tests/data/tdf129083.odt
new file mode 100644
index 000000000000..3de65273e8a1
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/tdf129083.odt differ
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 27ac5dbbef58..6c07f242f6a5 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1464,11 +1464,20 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt
             if ( SwTransferable::PasteData( rData, rSh, EXCHG_OUT_ACTION_INSERT_STRING, nActionFlags, SotClipboardFormatId::HTML,
                                         nDestination, false, false, nullptr, 0, false, nAnchorType, bIgnoreComments, &aPasteContext, ePasteTable) )
             {
-                pDispatch->Execute(FN_CHAR_LEFT, SfxCallMode::SYNCHRON);
-                pDispatch->Execute(FN_TABLE_SELECT_ALL, SfxCallMode::SYNCHRON);
-                pDispatch->Execute(SID_COPY, SfxCallMode::SYNCHRON);
+                bool bFoundTemporaryTable = false;
+                pDispatch->Execute(FN_LINE_UP, SfxCallMode::SYNCHRON);
+                if (rSh.GetDoc()->IsIdxInTable(rSh.GetCursor()->GetNode()) != nullptr)
+                {
+                    bFoundTemporaryTable = true;
+                    pDispatch->Execute(FN_TABLE_SELECT_ALL, SfxCallMode::SYNCHRON);
+                    pDispatch->Execute(SID_COPY, SfxCallMode::SYNCHRON);
+                }
                 for(sal_uInt32 a = 0; a < 1 + (nLevel * 2); a++)
                     pDispatch->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
+                // clipboard content hasn't changed (limit potential infinite
+                // recursion with the same non-native table, as was in tdf#138688)
+                if (!bFoundTemporaryTable)
+                    return false;
                 if (ePasteTable == PasteTableType::PASTE_TABLE)
                     pDispatch->Execute(FN_PASTE_NESTED_TABLE, SfxCallMode::SYNCHRON);
                 else if (ePasteTable == PasteTableType::PASTE_ROW)


More information about the Libreoffice-commits mailing list