summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-06-04 18:20:10 +0200
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2018-06-11 21:40:18 +0200
commitc40d3462cb138d5e665063fd7af8914545c5d27a (patch)
tree188198e2f720df49194d3ce378f7c8859d59aeb9 /dbaccess
parent447fe6b3231bd636aba84d77b0061eb06ed3999b (diff)
Properly decompose vnd.sun.star.pkg URL
When the URL encoded in the vnd.sun.star.pkg URL's authority contains a "@" (e.g., because it is a file URL denoting a pathname containging a "@" in one of the segments), that "@" need not be encoded (cf. the grammar at the top of tools/source/fsys/urlobj.cxx) and INetURLObject::GetHost would only return the part following the "@". When constructing sBaseURI in ODatabaseContext::loadObjectFromURL (dbaccess/source/core/dataaccess/databasecontext.cxx), the path part shall obviously not be decoded (but which the original code erroneously did). However, when obtaining sStreamRelPath in ODBFilter::implImport (dbaccess/source/filter/xml/xmlfilter.cxx), it isn't clear to me whether the path should be decoded, so I left that in (and added a TODO). (Caused `make CppunitTest_sw_uiwriter CPPUNIT_TEST_NAME=SwUiWriterTest::testEmbeddedDataSource` to fail when SRCDIR is such a pathname containing a "@" in one of the segments.) Change-Id: I6ffd842f3f3d37d2682e7cf14399fb3dbfa0a2aa Reviewed-on: https://gerrit.libreoffice.org/55286 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com> (cherry picked from commit e310ac4ab942feb014f3bb5bc4519dcf966b47fc) Reviewed-on: https://gerrit.libreoffice.org/55633 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/source/core/dataaccess/databasecontext.cxx24
-rw-r--r--dbaccess/source/filter/xml/xmlfilter.cxx40
2 files changed, 56 insertions, 8 deletions
diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx
index 974d431109d7..3f4a443abaa1 100644
--- a/dbaccess/source/core/dataaccess/databasecontext.cxx
+++ b/dbaccess/source/core/dataaccess/databasecontext.cxx
@@ -45,6 +45,7 @@
#include <com/sun/star/task/InteractionClassification.hpp>
#include <com/sun/star/ucb/InteractiveIOException.hpp>
#include <com/sun/star/ucb/IOErrorCode.hpp>
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
#include <com/sun/star/util/CloseVetoException.hpp>
#include <com/sun/star/util/XCloseable.hpp>
@@ -58,6 +59,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/exc_hlp.hxx>
+#include <rtl/uri.hxx>
#include <svl/filenotation.hxx>
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
@@ -363,8 +365,26 @@ Reference< XInterface > ODatabaseContext::loadObjectFromURL(const OUString& _rNa
if (bEmbeddedDataSource)
{
// In this case the host contains the real path, and the path is the embedded stream name.
- OUString sBaseURI = aURL.GetHost(INetURLObject::DecodeMechanism::WithCharset) + aURL.GetURLPath(INetURLObject::DecodeMechanism::WithCharset);
- aArgs.put("BaseURI", sBaseURI);
+ auto const uri = css::uri::UriReferenceFactory::create(m_aContext)->parse(_sURL);
+ if (uri.is() && uri->isAbsolute() && uri->isHierarchical()
+ && uri->hasAuthority() && !uri->hasQuery() && !uri->hasFragment())
+ {
+ auto const auth = uri->getAuthority();
+ auto const decAuth = rtl::Uri::decode(
+ auth, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
+ if (auth.isEmpty() == decAuth.isEmpty()) {
+ // Decoding of auth to UTF-8 succeeded:
+ OUString sBaseURI = decAuth + uri->getPath();
+ aArgs.put("BaseURI", sBaseURI);
+ } else {
+ SAL_WARN(
+ "dbaccess.core",
+ "<" << _sURL << "> cannot be parse as vnd.sun.star.pkg URL");
+ }
+ } else {
+ SAL_WARN(
+ "dbaccess.core", "<" << _sURL << "> cannot be parse as vnd.sun.star.pkg URL");
+ }
}
Sequence< PropertyValue > aResource( aArgs.getPropertyValues() );
diff --git a/dbaccess/source/filter/xml/xmlfilter.cxx b/dbaccess/source/filter/xml/xmlfilter.cxx
index 906a2bd69272..a77db0ecec0f 100644
--- a/dbaccess/source/filter/xml/xmlfilter.cxx
+++ b/dbaccess/source/filter/xml/xmlfilter.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <vcl/errinf.hxx>
+#include <com/sun/star/uri/UriReferenceFactory.hpp>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <com/sun/star/packages/WrongPasswordException.hpp>
#include <com/sun/star/packages/zip/ZipIOException.hpp>
@@ -61,6 +62,7 @@
#include <connectivity/DriversConfig.hxx>
#include <dsntypes.hxx>
#include <rtl/strbuf.hxx>
+#include <rtl/uri.hxx>
using namespace ::com::sun::star;
@@ -308,12 +310,38 @@ bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
OUString sStreamRelPath;
if (sFileName.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:"))
{
- // In this case the host contains the real path, and the path is the embedded stream name.
- INetURLObject aURL(sFileName);
- sFileName = aURL.GetHost(INetURLObject::DecodeMechanism::WithCharset);
- sStreamRelPath = aURL.GetURLPath(INetURLObject::DecodeMechanism::WithCharset);
- if (sStreamRelPath.startsWith("/"))
- sStreamRelPath = sStreamRelPath.copy(1);
+ // In this case the authority contains the real path, and the path is the embedded stream name.
+ auto const uri = css::uri::UriReferenceFactory::create(GetComponentContext())
+ ->parse(sFileName);
+ if (uri.is() && uri->isAbsolute() && uri->isHierarchical()
+ && uri->hasAuthority() && !uri->hasQuery() && !uri->hasFragment())
+ {
+ auto const auth = uri->getAuthority();
+ auto const decAuth = rtl::Uri::decode(
+ auth, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
+ auto path = uri->getPath();
+ if (!path.isEmpty()) {
+ assert(path[0] == '/');
+ path = path.copy(1);
+ }
+ auto const decPath = rtl::Uri::decode(
+ path, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
+ //TODO: really decode path?
+ if (auth.isEmpty() == decAuth.isEmpty() && path.isEmpty() == decPath.isEmpty())
+ {
+ // Decoding of auth and path to UTF-8 succeeded:
+ sFileName = decAuth;
+ sStreamRelPath = decPath;
+ } else {
+ SAL_WARN(
+ "dbaccess",
+ "<" << sFileName << "> cannot be parse as vnd.sun.star.pkg URL");
+ }
+ } else {
+ SAL_WARN(
+ "dbaccess",
+ "<" << sFileName << "> cannot be parse as vnd.sun.star.pkg URL");
+ }
}
pMedium = new SfxMedium(sFileName, (StreamMode::READ | StreamMode::NOCREATE));