Kaydet (Commit) a24da404 authored tarafından Jan Holesovsky's avatar Jan Holesovsky Kaydeden (comit) Stephan Bergmann

LOK: Cleanup absolutizing of URLs.

Thanks to Stephan Bergmann.

Change-Id: I22aa3bb827db28bce3eabebb9b8c514663fad860
Reviewed-on: https://gerrit.libreoffice.org/16795Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst bea39901
...@@ -26,8 +26,9 @@ ...@@ -26,8 +26,9 @@
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/process.h> #include <osl/process.h>
#include <osl/thread.h> #include <osl/thread.h>
#include <rtl/strbuf.hxx>
#include <rtl/bootstrap.hxx> #include <rtl/bootstrap.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/uri.hxx>
#include <cppuhelper/bootstrap.hxx> #include <cppuhelper/bootstrap.hxx>
#include <comphelper/dispatchcommand.hxx> #include <comphelper/dispatchcommand.hxx>
#include <comphelper/lok.hxx> #include <comphelper/lok.hxx>
...@@ -165,19 +166,23 @@ static OUString getUString(const char* pString) ...@@ -165,19 +166,23 @@ static OUString getUString(const char* pString)
static OUString getAbsoluteURL(const char* pURL) static OUString getAbsoluteURL(const char* pURL)
{ {
OUString aURL(getUString(pURL)); OUString aURL(getUString(pURL));
if (aURL.isEmpty())
// return unchanged if it likely is an URL already
if (aURL.indexOf("://") > 0)
return aURL; return aURL;
OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
// convert relative paths to absolute ones // convert relative paths to absolute ones
osl_getProcessWorkingDir(&sWorkingDir.pData); OUString aWorkingDir;
osl::FileBase::getFileURLFromSystemPath( aURL, sDocPathUrl ); osl_getProcessWorkingDir(&aWorkingDir.pData);
osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl); if (!aWorkingDir.endsWith("/"))
aWorkingDir += "/";
try {
return rtl::Uri::convertRelToAbs(aWorkingDir, aURL);
}
catch (const rtl::MalformedUriException &)
{
}
return sAbsoluteDocUrl; return OUString();
} }
extern "C" extern "C"
...@@ -349,6 +354,12 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, ...@@ -349,6 +354,12 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
OUString aURL(getAbsoluteURL(pURL)); OUString aURL(getAbsoluteURL(pURL));
if (aURL.isEmpty())
{
pLib->maLastExceptionMsg = "Filename to load was not provided.";
SAL_INFO("lok", "URL for load is empty");
return NULL;
}
pLib->maLastExceptionMsg.clear(); pLib->maLastExceptionMsg.clear();
...@@ -415,6 +426,12 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha ...@@ -415,6 +426,12 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
OUString sFormat = getUString(pFormat); OUString sFormat = getUString(pFormat);
OUString aURL(getAbsoluteURL(sUrl)); OUString aURL(getAbsoluteURL(sUrl));
if (aURL.isEmpty())
{
gImpl->maLastExceptionMsg = "Filename to save to was not provided.";
SAL_INFO("lok", "URL for save is empty");
return false;
}
try try
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment