Blob Blame History Raw
From 203eaebd472da9d8c83493331af698b2f9811b55 Mon Sep 17 00:00:00 2001
From: Jan Holesovsky <kendy@collabora.com>
Date: Mon, 6 Jul 2015 15:16:56 +0200
Subject: [PATCH 066/398] LOK: Cleanup absolutizing of URLs.

Thanks to Stephan Bergmann.

Change-Id: I22aa3bb827db28bce3eabebb9b8c514663fad860
(cherry picked from commit b183507ee293d8bcafa9c1c5b2844b7a83fea17b)
---
 desktop/source/lib/init.cxx | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index c08f1eec85de..63fe90b585b2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -166,19 +166,21 @@ static OUString getUString(const char* pString)
 static OUString getAbsoluteURL(const char* pURL)
 {
     OUString aURL(getUString(pURL));
-
-    // return unchanged if it likely is an URL already
-    if (aURL.indexOf("://") > 0)
+    if (aURL.isEmpty())
         return aURL;
 
-    OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
-
     // convert relative paths to absolute ones
-    osl_getProcessWorkingDir(&sWorkingDir.pData);
-    osl::FileBase::getFileURLFromSystemPath( aURL, sDocPathUrl );
-    osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
+    OUString aWorkingDir;
+    osl_getProcessWorkingDir(&aWorkingDir.pData);
+
+    try {
+        return rtl::Uri::convertRelToAbs(aWorkingDir + "/", aURL);
+    }
+    catch (const rtl::MalformedUriException &)
+    {
+    }
 
-    return sAbsoluteDocUrl;
+    return OUString();
 }
 
 extern "C"
@@ -350,6 +352,12 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
     SolarMutexGuard aGuard;
 
     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();
 
@@ -416,6 +424,12 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
 
     OUString sFormat = getUString(pFormat);
     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
     {
-- 
2.12.0