[Libreoffice-commits] core.git: extensions/source sw/qa sw/source

Mike Kaganski mike.kaganski at collabora.com
Mon Nov 13 17:24:18 UTC 2017


 extensions/source/abpilot/datasourcehandling.cxx |   17 +++++++++++------
 sw/qa/extras/inc/swmodeltestbase.hxx             |    2 +-
 sw/qa/extras/uiwriter/uiwriter.cxx               |    3 ++-
 sw/source/uibase/app/docsh.cxx                   |   14 +++++++++++---
 4 files changed, 25 insertions(+), 11 deletions(-)

New commits:
commit 3dee7948c732faf488846d4d3d1237e89afde28c
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Mon Nov 13 16:10:49 2017 +0300

    More proper construction of vnd.sun.star.pkg URL
    
    See commit bff8d843bd4e5dcca5dc1a60c2c7852b1b72a00b
    The SwUiWriterTest::testEmbeddedDataSource unit test is adjusted to
    test the paths with "#".
    
    Change-Id: I8d85147128915c7100ab9cc2888eb73c94fe6486
    Reviewed-on: https://gerrit.libreoffice.org/44678
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/extensions/source/abpilot/datasourcehandling.cxx b/extensions/source/abpilot/datasourcehandling.cxx
index 17d1ad154a23..cf95ac048086 100644
--- a/extensions/source/abpilot/datasourcehandling.cxx
+++ b/extensions/source/abpilot/datasourcehandling.cxx
@@ -38,6 +38,8 @@
 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
 #include <com/sun/star/task/InteractionHandler.hpp>
 #include <com/sun/star/uno/XNamingService.hpp>
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
+#include <com/sun/star/uri/VndSunStarPkgUrlReferenceFactory.hpp>
 
 #include <comphelper/interaction.hxx>
 #include <comphelper/processfactory.hxx>
@@ -63,7 +65,7 @@ OUString lcl_getOwnURL(SfxObjectShell const * pObjectShell)
         return aRet;
 
     const INetURLObject& rURLObject = pObjectShell->GetMedium()->GetURLObject();
-    aRet = rURLObject.GetMainURL(INetURLObject::DecodeMechanism::WithCharset);
+    aRet = rURLObject.GetMainURL(INetURLObject::DecodeMechanism::NONE);
     return aRet;
 }
 
@@ -353,8 +355,8 @@ namespace abp
             {
                 SfxViewFrame* pFrame = SfxViewFrame::Current();
                 SfxObjectShell* pObjectShell = pFrame ? pFrame->GetObjectShell() : nullptr;
-                OUString aOwnURL = lcl_getOwnURL(pObjectShell);
-                if (aOwnURL.isEmpty() || !rSettings.bEmbedDataSource || !pObjectShell)
+                OUString aOwnURL = lcl_getOwnURL(pObjectShell); // empty if pObjectShell is nullptr
+                if (aOwnURL.isEmpty() || !rSettings.bEmbedDataSource)
                 {
                     // Cannot or should not embed.
                     xStorable->storeAsURL(m_pImpl->sName,Sequence<PropertyValue>());
@@ -363,9 +365,12 @@ namespace abp
                 {
                     // Embed.
                     OUString aStreamRelPath = "EmbeddedDatabase";
-                    OUString sTmpName = "vnd.sun.star.pkg://";
-                    sTmpName += INetURLObject::encode(aOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::EncodeMechanism::All);
-                    sTmpName += "/" + aStreamRelPath;
+                    auto xContext(comphelper::getProcessComponentContext());
+                    auto xUri = css::uri::UriReferenceFactory::create(xContext)->parse(aOwnURL);
+                    assert(xUri.is());
+                    xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)->createVndSunStarPkgUrlReference(xUri);
+                    assert(xUri.is());
+                    OUString const sTmpName = xUri->getUriReference() + "/" + aStreamRelPath;
                     uno::Reference<embed::XStorage> xStorage = pObjectShell->GetStorage();
                     uno::Sequence<beans::PropertyValue> aSequence = comphelper::InitPropertySequence(
                     {
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 09fe3589b9a8..3d791eca7a47 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -791,7 +791,7 @@ protected:
         std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true));
 
         xmlDocPtr pXmlDoc = parseXmlStream(pStream.get());
-        pXmlDoc->name = reinterpret_cast<char *>(xmlStrdup(reinterpret_cast<xmlChar const *>(OUStringToOString(maTempFile.GetURL(), RTL_TEXTENCODING_UTF8).getStr())));
+        pXmlDoc->name = reinterpret_cast<char *>(xmlStrdup(reinterpret_cast<xmlChar const *>(OUStringToOString(url, RTL_TEXTENCODING_UTF8).getStr())));
         return pXmlDoc;
     }
 
diff --git a/sw/qa/extras/uiwriter/data/calc-data-source.ods b/sw/qa/extras/uiwriter/data/hash#path/calc-data-source.ods
similarity index 100%
rename from sw/qa/extras/uiwriter/data/calc-data-source.ods
rename to sw/qa/extras/uiwriter/data/hash#path/calc-data-source.ods
diff --git a/sw/qa/extras/uiwriter/data/embedded-data-source.odt b/sw/qa/extras/uiwriter/data/hash#path/embedded-data-source.odt
similarity index 100%
rename from sw/qa/extras/uiwriter/data/embedded-data-source.odt
rename to sw/qa/extras/uiwriter/data/hash#path/embedded-data-source.odt
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 202c91cd9069..34f0e21466d1 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -3681,7 +3681,8 @@ void SwUiWriterTest::testEmbeddedDataSource()
     CPPUNIT_ASSERT(!xDatabaseContext->hasByName("calc-data-source"));
 
     // Load: should have a component and a data source, too.
-    load(DATA_DIRECTORY, "embedded-data-source.odt");
+    // Path with "#" must not cause issues
+    load(DATA_DIRECTORY + OUStringLiteral("hash%23path/"), "embedded-data-source.odt");
     CPPUNIT_ASSERT(mxComponent.is());
     CPPUNIT_ASSERT(xDatabaseContext->hasByName("calc-data-source"));
 
diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index 8f50bc411834..b1ae1e37b2da 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -118,6 +118,8 @@
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/sdb/DatabaseContext.hpp>
 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
+#include <com/sun/star/uri/VndSunStarPkgUrlReferenceFactory.hpp>
 
 #include <unomid.h>
 #include <unotextrange.hxx>
@@ -428,9 +430,15 @@ bool SwDocShell::SaveAs( SfxMedium& rMedium )
         uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext());
 
         const INetURLObject& rOldURLObject = GetMedium()->GetURLObject();
-        OUString aURL = "vnd.sun.star.pkg://";
-        aURL += INetURLObject::encode(rOldURLObject.GetMainURL(INetURLObject::DecodeMechanism::WithCharset), INetURLObject::PART_AUTHORITY, INetURLObject::EncodeMechanism::All);
-        aURL += "/" + INetURLObject::encode(m_xDoc->GetDBManager()->getEmbeddedName(), INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All);
+        auto xContext(comphelper::getProcessComponentContext());
+        auto xUri = css::uri::UriReferenceFactory::create(xContext)
+            ->parse(rOldURLObject.GetMainURL(INetURLObject::DecodeMechanism::NONE));
+        assert(xUri.is());
+        xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)->createVndSunStarPkgUrlReference(xUri);
+        assert(xUri.is());
+        OUString const aURL = xUri->getUriReference() + "/"
+            + INetURLObject::encode(m_xDoc->GetDBManager()->getEmbeddedName(),
+                INetURLObject::PART_FPATH, INetURLObject::EncodeMechanism::All);
 
         uno::Reference<sdb::XDocumentDataSource> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY);
         uno::Reference<frame::XStorable> xStorable(xDataSource->getDatabaseDocument(), uno::UNO_QUERY);


More information about the Libreoffice-commits mailing list