summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-08-24 09:59:42 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2017-08-25 09:58:15 +0200
commit51e610e584e09ecdec4cbc5c7c550bc806d7ee1c (patch)
treef4811e90caf1542a3d909758d3d2c3b4477df5fc
parentf0b0123fa3f70ede8592befcd01381542db76617 (diff)
tdf#111876 Save correct relative links in Calc
Relative links were saved as: file:///a/file.odt instead of: ../a/file.odt Relative path was based on source document, not target. Unit test contains spreadsheet with relative link to the "../xls/bug-fixes.xls" file. Change-Id: I803b7b8936bde9644ae5760756ee7249677f2641 Reviewed-on: https://gerrit.libreoffice.org/41500 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rwxr-xr-xsc/qa/unit/data/xlsx/tdf111876.xlsxbin0 -> 9019 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx22
-rw-r--r--sc/source/filter/excel/xecontent.cxx15
-rw-r--r--sc/source/filter/excel/xestream.cxx4
4 files changed, 38 insertions, 3 deletions
diff --git a/sc/qa/unit/data/xlsx/tdf111876.xlsx b/sc/qa/unit/data/xlsx/tdf111876.xlsx
new file mode 100755
index 000000000000..a12f14c3b008
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/tdf111876.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 45f56d08fa03..10031f9f5b86 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -94,6 +94,7 @@ public:
ScDocShellRef saveAndReloadPassword( ScDocShell*, const OUString&, const OUString&, const OUString&, SfxFilterFlags );
void test();
+ void testTdf111876();
void testPasswordExportODS();
void testConditionalFormatExportODS();
void testConditionalFormatExportXLSX();
@@ -206,6 +207,7 @@ public:
CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test);
+ CPPUNIT_TEST(testTdf111876);
CPPUNIT_TEST(testPasswordExportODS);
CPPUNIT_TEST(testConditionalFormatExportODS);
CPPUNIT_TEST(testConditionalFormatExportXLSX);
@@ -396,6 +398,26 @@ void ScExportTest::test()
xDocSh->DoClose();
}
+void ScExportTest::testTdf111876()
+ {
+ // DOcument with relative path hyperlink
+
+ ScDocShellRef xShell = loadDoc("tdf111876.", FORMAT_XLSX);
+ CPPUNIT_ASSERT(xShell.is());
+
+ ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX);
+ CPPUNIT_ASSERT(xDocSh.is());
+
+ xmlDocPtr pDoc = XPathHelper::parseExport(*xDocSh, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels", FORMAT_XLSX);
+ CPPUNIT_ASSERT(pDoc);
+ OUString sTarget = getXPath(pDoc, "/r:Relationships/r:Relationship", "Target");
+
+ // Document is saved to the temporary directory, relative path should be different than original one
+ CPPUNIT_ASSERT(sTarget != "../xls/bug-fixes.xls");
+
+ xDocSh->DoClose();
+}
+
void ScExportTest::testPasswordExportODS()
{
ScDocShell* pShell = new ScDocShell(
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 5a0045753612..4814bde09dfd 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -386,9 +386,18 @@ XclExpHyperlink::XclExpHyperlink( const XclExpRoot& rRoot, const SvxURLField& rU
m_Repr = aFileName;
msTarget = XclXmlUtils::ToOUString( aLink );
- // ooxml expects the file:/// part appended ( or at least
- // ms2007 does, ms2010 is more tolerant )
- msTarget = "file:///" + msTarget;
+
+ if( bRel )
+ {
+ for( int i = 0; i < nLevel; ++i )
+ msTarget = "../" + msTarget;
+ }
+ else
+ {
+ // ooxml expects the file:/// part appended ( or at least
+ // ms2007 does, ms2010 is more tolerant )
+ msTarget = "file:///" + msTarget;
+ }
}
else if( eProtocol != INetProtocol::NotValid )
{
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index e4ef28b4e4dd..52e4d5b34056 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -1060,6 +1060,10 @@ bool XclExpXmlStream::exportDocument()
aData.maMaxPos.SetRow( ::std::min( aData.maScMaxPos.Row(), aData.maXclMaxPos.Row() ) );
aData.maMaxPos.SetTab( ::std::min( aData.maScMaxPos.Tab(), aData.maXclMaxPos.Tab() ) );
aData.mpCompileFormulaCxt.reset( new sc::CompileFormulaContext(&rDoc) );
+ // set target path to get correct relative links to target document, not source
+ INetURLObject aPath(getFileUrl());
+ aData.maBasePath = aPath.GetPath() + "\\";
+ aData.maBasePath = "file:///" + aData.maBasePath.replace('\\', '/');
XclExpRoot aRoot( aData );