summaryrefslogtreecommitdiff
path: root/sc/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-07-05 12:29:18 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-07-05 14:04:11 +0200
commitdb1c8df98a23d687d6806f371bdd416dd1b84589 (patch)
treed99aaab6f7bd965c16f47fca2577c5bf4a92b99c /sc/qa
parentbec391133da18e1c7c0e7f3d562bceeb6f93b497 (diff)
XLSX import: fix handling of named ranges referring to PathMissing sheets
In case xl/externalLinks/externalLink1.xml refers to a sheet where type is PathMissing, then both <sheetName> and <sheetData> gets ignored on import. Make sure to also ignore named ranges referring to such external documents. The resulting named range was just a string anyway, and exporting this back to XLSX results in Excel marking the whole file as corrupted. Change-Id: Ifde07b5e59fba371f1f8ab3e82861c6997c6dbf0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118401 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sc/qa')
-rw-r--r--sc/qa/unit/data/xlsx/invalid-named-range.xlsxbin0 -> 9605 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test2.cxx19
2 files changed, 19 insertions, 0 deletions
diff --git a/sc/qa/unit/data/xlsx/invalid-named-range.xlsx b/sc/qa/unit/data/xlsx/invalid-named-range.xlsx
new file mode 100644
index 000000000000..53feabec382f
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/invalid-named-range.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test2.cxx b/sc/qa/unit/subsequent_export-test2.cxx
index d23145c67cf2..ad08aa2802d0 100644
--- a/sc/qa/unit/subsequent_export-test2.cxx
+++ b/sc/qa/unit/subsequent_export-test2.cxx
@@ -189,6 +189,7 @@ public:
void testTdf140431();
void testCheckboxFormControlXlsxExport();
void testButtonFormControlXlsxExport();
+ void testInvalidNamedRange();
CPPUNIT_TEST_SUITE(ScExportTest2);
@@ -286,6 +287,7 @@ public:
CPPUNIT_TEST(testTdf140431);
CPPUNIT_TEST(testCheckboxFormControlXlsxExport);
CPPUNIT_TEST(testButtonFormControlXlsxExport);
+ CPPUNIT_TEST(testInvalidNamedRange);
CPPUNIT_TEST_SUITE_END();
@@ -2348,6 +2350,23 @@ void ScExportTest2::testButtonFormControlXlsxExport()
assertXPathContent(pDoc, "//x:anchor/x:to/xdr:row", "7");
}
+void ScExportTest2::testInvalidNamedRange()
+{
+ // Given a document which has a named range (myname) that refers to the "1" external link, but
+ // the link's type is xlPathMissing, when importing that document:
+ ScDocShellRef xDocSh = loadDoc(u"invalid-named-range.", FORMAT_XLSX);
+ CPPUNIT_ASSERT(xDocSh.is());
+
+ // Then make sure that named range is ignored, as "1" can't be resolved, and exporting it back
+ // to XLSX (without the xlPathMissing link) would corrupt the document:
+ uno::Reference<beans::XPropertySet> xDocProps(xDocSh->GetModel(), uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xNamedRanges(xDocProps->getPropertyValue("NamedRanges"),
+ uno::UNO_QUERY);
+ // Without the fix in place, this test would have failed, we didn't ignore the problematic named
+ // range on import.
+ CPPUNIT_ASSERT(!xNamedRanges->hasByName("myname"));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest2);
CPPUNIT_PLUGIN_IMPLEMENT();