[Libreoffice-commits] core.git: sc/qa sc/source
Justin Luth
justin_luth at sil.org
Thu May 25 21:30:03 UTC 2017
sc/qa/unit/data/ods/tdf99856_dataValidationTest.ods |binary
sc/qa/unit/subsequent_export-test.cxx | 24 ++++++++++++++++++++
sc/source/filter/excel/xecontent.cxx | 10 ++++++++
3 files changed, 34 insertions(+)
New commits:
commit b139bf96574010f317c543bc45d23dd6a5810621
Author: Justin Luth <justin_luth at sil.org>
Date: Thu May 25 20:47:03 2017 +0300
tdf#99856 xlsx export: limit dataValidation list to 255 chars
Excel consider the file corrupt if it has an overly long
validation list.
Change-Id: I4145859d4f76e0a70521c7bee33c96927b437ace
Reviewed-on: https://gerrit.libreoffice.org/38038
Reviewed-by: Justin Luth <justin_luth at sil.org>
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>
diff --git a/sc/qa/unit/data/ods/tdf99856_dataValidationTest.ods b/sc/qa/unit/data/ods/tdf99856_dataValidationTest.ods
new file mode 100644
index 000000000000..4faf626c1c67
Binary files /dev/null and b/sc/qa/unit/data/ods/tdf99856_dataValidationTest.ods differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 49e52a512a88..56851089e728 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -43,6 +43,7 @@
#include <dpobject.hxx>
#include <dpsave.hxx>
#include <dputil.hxx>
+#include "validat.hxx"
#include <svx/svdoole2.hxx>
#include <svx/svdpage.hxx>
@@ -94,6 +95,7 @@ public:
void testPasswordExportODS();
void testConditionalFormatExportODS();
void testConditionalFormatExportXLSX();
+ void testTdf99856_dataValidationTest();
void testColorScaleExportODS();
void testColorScaleExportXLSX();
void testDataBarExportODS();
@@ -201,6 +203,7 @@ public:
CPPUNIT_TEST(testPasswordExportODS);
CPPUNIT_TEST(testConditionalFormatExportODS);
CPPUNIT_TEST(testConditionalFormatExportXLSX);
+ CPPUNIT_TEST(testTdf99856_dataValidationTest);
CPPUNIT_TEST(testColorScaleExportODS);
CPPUNIT_TEST(testColorScaleExportXLSX);
CPPUNIT_TEST(testDataBarExportODS);
@@ -451,6 +454,27 @@ void ScExportTest::testConditionalFormatExportXLSX()
xDocSh->DoClose();
}
+void ScExportTest::testTdf99856_dataValidationTest()
+{
+ ScDocShellRef xShell = loadDoc("tdf99856_dataValidationTest.", FORMAT_ODS);
+ CPPUNIT_ASSERT_MESSAGE("Failed to load doc", xShell.is());
+
+ ScDocShellRef xDocSh = saveAndReload( xShell.get(), FORMAT_XLSX);
+ CPPUNIT_ASSERT_MESSAGE("Failed to reload doc", xDocSh.is());
+
+ ScDocument& rDoc = xDocSh->GetDocument();
+ const ScValidationData* pData = rDoc.GetValidationEntry(2);
+ CPPUNIT_ASSERT(pData);
+
+ // Excel can't open corrupt file if the list is longer than 255 characters
+ std::vector<ScTypedStrData> aList;
+ pData->FillSelectionList(aList, ScAddress(0, 1, 1));
+ CPPUNIT_ASSERT_EQUAL(size_t(18), aList.size());
+ CPPUNIT_ASSERT_EQUAL(OUString("18 Missi"), aList[17].GetString());
+
+ xDocSh->DoClose();
+}
+
void ScExportTest::testColorScaleExportODS()
{
ScDocShellRef xShell = loadDoc("colorscale.", FORMAT_ODS);
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 81fe1e9a922b..4c5907c26f93 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -1671,6 +1671,16 @@ XclExpDV::XclExpDV( const XclExpRoot& rRoot, sal_uLong nScHandle ) :
}
::set_flag( mnFlags, EXC_DV_STRINGLIST );
+ // maximum length allowed in Excel is 255 characters, and don't end with an empty token
+ sal_uInt32 nLen = sFormulaBuf.getLength();
+ if( nLen > 256 ) // 255 + beginning quote mark
+ {
+ nLen = 255;
+ if( sFormulaBuf[nLen - 1] == ',' )
+ --nLen;
+ sFormulaBuf = sFormulaBuf.copy(0, nLen);
+ }
+
sFormulaBuf.append( '"' );
msFormula1 = sFormulaBuf.makeStringAndClear();
}
More information about the Libreoffice-commits
mailing list