[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sc/qa sc/source

Szymon Kłos szymon.klos at collabora.com
Fri Aug 25 14:08:35 UTC 2017


 sc/qa/unit/data/xlsx/tdf111876.xlsx   |binary
 sc/qa/unit/subsequent_export-test.cxx |   22 ++++++++++++++++++++++
 sc/source/filter/excel/xecontent.cxx  |   15 ++++++++++++---
 sc/source/filter/excel/xestream.cxx   |    4 ++++
 4 files changed, 38 insertions(+), 3 deletions(-)

New commits:
commit 6273f015108ffb10c40f97604a11ce2e3ec0a06d
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Thu Aug 24 09:59:42 2017 +0200

    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 at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/41555
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

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
Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf111876.xlsx differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 514f08c68a54..caa0f07815f0 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -90,6 +90,7 @@ public:
 
     void test();
     void testPasswordExport();
+    void testTdf111876();
     void testConditionalFormatExportODS();
     void testConditionalFormatExportXLSX();
     void testColorScaleExportODS();
@@ -195,6 +196,7 @@ public:
     CPPUNIT_TEST_SUITE(ScExportTest);
     CPPUNIT_TEST(test);
     CPPUNIT_TEST(testPasswordExport);
+    CPPUNIT_TEST(testTdf111876);
     CPPUNIT_TEST(testConditionalFormatExportODS);
     CPPUNIT_TEST(testConditionalFormatExportXLSX);
     CPPUNIT_TEST(testColorScaleExportODS);
@@ -378,6 +380,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::testPasswordExport()
 {
     ScDocShell* pShell = new ScDocShell(
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index fa5f336329e2..ac6be4e26cd9 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -382,9 +382,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 58d9c761f7af..82d4c4d20479 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -1076,6 +1076,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 );
 


More information about the Libreoffice-commits mailing list