summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-08-15 12:35:30 +0300
committerAron Budea <aron.budea@collabora.com>2018-08-20 06:26:18 +0200
commit7a0cad5a5667406b37b9ad6ec1e86d79784ce0ee (patch)
tree565a158c04b1da8993bf2ea84f3786d0447bc207 /sc
parentcb2025559c6573472079a0dc4142e99a5e3087c8 (diff)
tdf#118990: use full URI for absolute references
Previously (since commit 7eb5e135422f1a5830a44d129300bc3fafb4627d) only path relative to reference host was stored, and host itself was dropped. That resulted in URIs like "/share/file.xlsx", even without scheme. For Windows shares, this broke UNC paths like "\\HOSTNAME\share\file.xlsx" (which are stored in XLSX by Excel as "file:///\\HOSTNAME\share\file.xlsx"), and on subsequent import, this resulted in paths on the same drive as the document (like "C:\share\file.xlsx"). With this change, we will store "file://HOSTNAME/share/file.xlsx", which is correctly processed by both LibreOffice and MS Excel. Reviewed-on: https://gerrit.libreoffice.org/59064 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit f24b0ec13c5c8edda5ffb1336b0eb6da173dfc97) Change-Id: I3f13aa0b3ae8dc41ec28eaa1416d536469c4562a Reviewed-on: https://gerrit.libreoffice.org/59166 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Aron Budea <aron.budea@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/data/xlsx/tdf118990.xlsxbin0 -> 12143 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx33
-rw-r--r--sc/source/filter/excel/xecontent.cxx3
3 files changed, 35 insertions, 1 deletions
diff --git a/sc/qa/unit/data/xlsx/tdf118990.xlsx b/sc/qa/unit/data/xlsx/tdf118990.xlsx
new file mode 100644
index 000000000000..b680edceef0e
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/tdf118990.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 916eea9229c1..2370836399a8 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -206,6 +206,8 @@ public:
void testHiddenRepeatedRowsODS();
void testHyperlinkTargetFrameODS();
+ void testTdf118990();
+
CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test);
CPPUNIT_TEST(testTdf111876);
@@ -311,6 +313,8 @@ public:
CPPUNIT_TEST(testHiddenRepeatedRowsODS);
CPPUNIT_TEST(testHyperlinkTargetFrameODS);
+ CPPUNIT_TEST(testTdf118990);
+
CPPUNIT_TEST_SUITE_END();
private:
@@ -3996,6 +4000,35 @@ void ScExportTest::testHyperlinkTargetFrameODS()
CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrameExport);
}
+void ScExportTest::testTdf118990()
+{
+ ScDocShellRef xDocSh = loadDoc("tdf118990.", FORMAT_XLSX);
+ CPPUNIT_ASSERT(xDocSh.is());
+ xDocSh = saveAndReload(xDocSh.get(), FORMAT_XLSX);
+ ScDocument& rDoc = xDocSh->GetDocument();
+
+ // TODO: also test A1, which contains a UNC reference to \\localhost\share\lookupsource.xlsx,
+ // but currently looses "localhost" part when normalized in INetURLObject, becoming
+ // file:///share/lookupsource.xlsx - which is incorrect, since it points to local filesystem
+ // and not to Windows network share.
+
+#if defined LINUX // following INetURLObject::setAbsURIRef
+#define TDF118990_SCHEME "smb:"
+#else // for Windows and macOS
+#define TDF118990_SCHEME "file:"
+#endif
+
+ ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 1, 0),
+ "VLOOKUP(B1,'" TDF118990_SCHEME "//192.168.1.1/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)",
+ "Wrong Windows share (using host IP) URL in A2");
+
+ ASSERT_FORMULA_EQUAL(rDoc, ScAddress(0, 2, 0),
+ "VLOOKUP(B1,'" TDF118990_SCHEME "//NETWORKHOST/share/lookupsource.xlsx'#$Sheet1.A1:B5,2)",
+ "Wrong Windows share (using hostname) URL in A3");
+
+ xDocSh->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 29523aa81c9d..b79815d67781 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -459,7 +459,8 @@ OUString XclExpHyperlink::BuildFileName(
sal_uInt16& rnLevel, bool& rbRel, const OUString& rUrl, const XclExpRoot& rRoot, bool bEncoded )
{
INetURLObject aURLObject( rUrl );
- OUString aDosName( bEncoded ? aURLObject.GetURLPath() : aURLObject.getFSysPath( FSysStyle::Dos ) );
+ OUString aDosName(bEncoded ? aURLObject.GetMainURL(INetURLObject::DecodeMechanism::ToIUri)
+ : aURLObject.getFSysPath(FSysStyle::Dos));
rnLevel = 0;
rbRel = rRoot.IsRelUrl();