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

Mike Kaganski mike.kaganski at collabora.com
Wed May 9 08:26:11 UTC 2018


 sw/qa/extras/rtfexport/data/tdf117268.rtf       |   35 ++++++++++++++++++++++
 sw/qa/extras/rtfexport/rtfexport.cxx            |   38 ++++++++++++++++++++++++
 writerfilter/source/rtftok/rtfdispatchvalue.cxx |    7 ++++
 3 files changed, 80 insertions(+)

New commits:
commit 6f1781cb1e0209aa2d2fcaaf4f1adbd4c36d7f54
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Thu May 3 15:09:40 2018 +0300

    tdf#117268: treat erroneous \itap0 the same way as Word does
    
    ... so that if we are inside a table, it would not convert table
    paragraphs into top-level paragraphs. (The in-the-wild documents
    with this invalid input are, e.g., generated by Consultant+ legal
    reference database).
    
    Reviewed-on: https://gerrit.libreoffice.org/53790
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    (cherry picked from commit 247dabcb0b92a62b233ec0237deac84e6675325c)
    
    Change-Id: I45eb9073a0651bc963badb84229ce5ae437f1a8c
    Reviewed-on: https://gerrit.libreoffice.org/53840
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    Tested-by: Michael Stahl <Michael.Stahl at cib.de>

diff --git a/sw/qa/extras/rtfexport/data/tdf117268.rtf b/sw/qa/extras/rtfexport/data/tdf117268.rtf
new file mode 100644
index 000000000000..608ea65637cc
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf117268.rtf
@@ -0,0 +1,35 @@
+{\rtf1
+{\trowd
+\clbrdrl\brdrs\brdrw10\clbrdrr\brdrs\brdrw10\clbrdrt\brdrs\brdrw10\clbrdrb\brdrs\brdrw10\cellx2000
+\pard
+Text 1
+\itap0
+\cell
+\row}
+\pard
+\par
+\itap0
+{\trowd
+\clbrdrl\brdrs\brdrw10\clbrdrr\brdrs\brdrw10\clbrdrt\brdrs\brdrw10\clbrdrb\brdrs\brdrw10\cellx2000
+\pard
+Text 2
+\itap0
+\cell
+\row}
+\itap0
+{\trowd
+\clbrdrl\brdrs\brdrw10\clbrdrr\brdrs\brdrw10\clbrdrt\brdrs\brdrw10\clbrdrb\brdrs\brdrw10\cellx2000
+\pard
+\itap2
+Text 3
+\nestcell
+\itap2
+{\nesttableprops\trowd
+\clbrdrl\brdrs\brdrw10\clbrdrr\brdrs\brdrw10\clbrdrt\brdrs\brdrw10\clbrdrb\brdrs\brdrw10\cellx1000
+\nestrow}
+\itap0
+\cell
+\row}
+\itap0
+\par
+}
\ No newline at end of file
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index ebc700c194f4..fd25f1cefe3d 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -30,6 +30,7 @@
 #include <com/sun/star/text/RubyAdjust.hpp>
 #include <com/sun/star/text/XTextColumns.hpp>
 #include <com/sun/star/text/HoriOrientation.hpp>
+#include <com/sun/star/text/XTextRangeCompare.hpp>
 
 #include <vcl/svapp.hxx>
 
@@ -1331,6 +1332,43 @@ DECLARE_RTFEXPORT_TEST(testTdf113202, "tdf113202.rtf")
     CPPUNIT_ASSERT(getProperty<bool>(getParagraph(4), "ParaContextMargin"));
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf117268, "tdf117268.rtf")
+{
+    // Here we check that we correctly mimic Word's treatment of erroneous \itap0 inside tables.
+    // Previously, the first table was import as text, and second top-level one only imported
+    // last row with nested table (first row was also imported as text).
+    uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY_THROW);
+    uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
+                                                    uno::UNO_QUERY_THROW);
+
+    // First (simple) table
+    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
+    uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(OUString("Text 1"), xCell->getString());
+
+    // Nested table
+    xTable.set(xTables->getByIndex(1), uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
+    xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(OUString("Text 3"), xCell->getString());
+    uno::Reference<beans::XPropertySet> xNestedAnchor(xTable->getAnchor(), uno::UNO_QUERY_THROW);
+    uno::Reference<text::XTextRange> xAnchorCell(xNestedAnchor->getPropertyValue("Cell"),
+                                                 uno::UNO_QUERY_THROW);
+
+    // Outer table
+    xTable.set(xTables->getByIndex(2), uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount());
+    xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(OUString("Text 2"), xCell->getString());
+    xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY_THROW);
+    uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xCell, uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextRangeCompare->compareRegionStarts(xAnchorCell, xCell));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index 20379b4ef45f..3e1fd25b7b6a 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -228,6 +228,13 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
     {
     case RTF_ITAP:
         nSprm = NS_ooxml::LN_tblDepth;
+        // tdf#117268: If \itap0 is encountered inside tables (between \cellxN and \cell), then
+        // use the default value (1), as Word apparently does
+        if (nParam == 0 && (m_nTopLevelCells != 0 || m_nNestedCells != 0))
+        {
+            nParam = 1;
+            pIntValue = std::make_shared<RTFValue>(nParam);
+        }
         break;
     default:
         break;


More information about the Libreoffice-commits mailing list