chart2/qa/extras/chart2import.cxx            |   43 +++++++++++++++++++++++++++
 chart2/qa/extras/data/docx/tdf139658.docx    |binary
 chart2/source/tools/InternalDataProvider.cxx |   12 ++++++-
 3 files changed, 53 insertions(+), 2 deletions(-)

New commits:
commit 41ec18183acbe6cf82b79e5b150eaf7b2b5f3a62
Author:     Tünde Tóth <toth.tu...@nisz.hu>
AuthorDate: Fri Jun 4 13:10:51 2021 +0200
Commit:     Tünde Tóth <toth.tu...@nisz.hu>
CommitDate: Thu Oct 21 10:52:24 2021 +0200

    tdf#139658 OOXML: fix broken chart import at labels with quotes
    
    During the import of the internal data table, incomplete
    parsing of category labels with escaped quotation marks
    resulted broken category labels and charts.
    
    Change-Id: If5af3d527b80d1e055562f589bdaf17096ad49f3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116714
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123893
    Tested-by: Tünde Tóth <toth.tu...@nisz.hu>
    Reviewed-by: Tünde Tóth <toth.tu...@nisz.hu>

diff --git a/chart2/qa/extras/chart2import.cxx 
b/chart2/qa/extras/chart2import.cxx
index fe9ebb5bc502..d891756da179 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -174,6 +174,8 @@ public:
     void testTdf137734();
     void testTdf137874();
     void testTdfCustomShapePos();
+    void testTdf121281();
+    void testTdf139658();
 
     CPPUNIT_TEST_SUITE(Chart2ImportTest);
     CPPUNIT_TEST(Fdo60083);
@@ -295,6 +297,8 @@ public:
     CPPUNIT_TEST(testTdf137734);
     CPPUNIT_TEST(testTdf137874);
     CPPUNIT_TEST(testTdfCustomShapePos);
+    CPPUNIT_TEST(testTdf121281);
+    CPPUNIT_TEST(testTdf139658);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -2845,6 +2849,45 @@ void Chart2ImportTest::testTdfCustomShapePos()
     }
 }
 
+void Chart2ImportTest::testTdf121281()
+{
+    load(u"/chart2/qa/extras/data/xlsx/", "incorrect_label_position.xlsx");
+    Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, 
mxComponent),
+                                               UNO_QUERY_THROW);
+    Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, 
UNO_QUERY_THROW);
+    Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), 
UNO_SET_THROW);
+    Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), 
UNO_QUERY_THROW);
+    Reference<drawing::XShape> xDataPointLabel(
+        getShapeByName(xShapes,
+                       
"CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"),
+        UNO_SET_THROW);
+
+    CPPUNIT_ASSERT(xDataPointLabel.is());
+    awt::Point aLabelPosition = xDataPointLabel->getPosition();
+    // This failed, if the data label flowed out of the chart area.
+    CPPUNIT_ASSERT_GREATEREQUAL(static_cast<sal_Int32>(0), aLabelPosition.Y);
+}
+
+void Chart2ImportTest::testTdf139658()
+{
+    load(u"/chart2/qa/extras/data/docx/", "tdf139658.docx");
+    uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xChartDoc.is());
+    Reference<chart2::XInternalDataProvider> 
xInternalProvider(xChartDoc->getDataProvider(),
+                                                               uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xInternalProvider.is());
+
+    Reference<chart::XComplexDescriptionAccess> xDescAccess(xInternalProvider, 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xDescAccess.is());
+
+    // Get the category labels.
+    Sequence<OUString> aCategories = xDescAccess->getRowDescriptions();
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aCategories.getLength());
+    CPPUNIT_ASSERT_EQUAL(OUString("category1"), aCategories[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString("\"category2\""), aCategories[1]);
+    CPPUNIT_ASSERT_EQUAL(OUString("category\"3"), aCategories[2]);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/docx/tdf139658.docx 
b/chart2/qa/extras/data/docx/tdf139658.docx
new file mode 100644
index 000000000000..59deda9f83f9
Binary files /dev/null and b/chart2/qa/extras/data/docx/tdf139658.docx differ
diff --git a/chart2/source/tools/InternalDataProvider.cxx 
b/chart2/source/tools/InternalDataProvider.cxx
index c1d0008098ab..415f08ac3ea9 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -518,7 +518,14 @@ InternalDataProvider::createDataSequenceFromArray( const 
OUString& rArrayStr, co
     bool bInQuote = false;
     for (; p != pEnd; ++p)
     {
-        if (*p == '"')
+        // Skip next "" within the title text: it's an escaped double 
quotation mark.
+        if (bInQuote && *p == '"' && *(p + 1) == '"')
+        {
+            if (!pElem)
+                pElem = p;
+            ++p;
+        }
+        else if (*p == '"')
         {
             bInQuote = !bInQuote;
             if (bInQuote)
@@ -534,7 +541,8 @@ InternalDataProvider::createDataSequenceFromArray( const 
OUString& rArrayStr, co
                 // Non empty string
                 if (!aElem.isEmpty())
                     bAllNumeric = false;
-                aRawElems.push_back(aElem);
+                // Restore also escaped double quotation marks
+                aRawElems.push_back(aElem.replaceAll("\"\"", "\""));
                 pElem = nullptr;
                 aElem.clear();
 

Reply via email to