135360
From 203eaebd472da9d8c83493331af698b2f9811b55 Mon Sep 17 00:00:00 2001
135360
From: Jan Holesovsky <kendy@collabora.com>
135360
Date: Mon, 6 Jul 2015 15:16:56 +0200
135360
Subject: [PATCH 066/398] LOK: Cleanup absolutizing of URLs.
135360
135360
Thanks to Stephan Bergmann.
135360
135360
Change-Id: I22aa3bb827db28bce3eabebb9b8c514663fad860
135360
(cherry picked from commit b183507ee293d8bcafa9c1c5b2844b7a83fea17b)
135360
---
135360
 desktop/source/lib/init.cxx | 32 +++++++++++++++++++++++---------
135360
 1 file changed, 23 insertions(+), 9 deletions(-)
135360
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index c08f1eec85de..63fe90b585b2 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -166,19 +166,21 @@ static OUString getUString(const char* pString)
135360
 static OUString getAbsoluteURL(const char* pURL)
135360
 {
135360
     OUString aURL(getUString(pURL));
135360
-
135360
-    // return unchanged if it likely is an URL already
135360
-    if (aURL.indexOf("://") > 0)
135360
+    if (aURL.isEmpty())
135360
         return aURL;
135360
 
135360
-    OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
135360
-
135360
     // convert relative paths to absolute ones
135360
-    osl_getProcessWorkingDir(&sWorkingDir.pData);
135360
-    osl::FileBase::getFileURLFromSystemPath( aURL, sDocPathUrl );
135360
-    osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
135360
+    OUString aWorkingDir;
135360
+    osl_getProcessWorkingDir(&aWorkingDir.pData);
135360
+
135360
+    try {
135360
+        return rtl::Uri::convertRelToAbs(aWorkingDir + "/", aURL);
135360
+    }
135360
+    catch (const rtl::MalformedUriException &)
135360
+    {
135360
+    }
135360
 
135360
-    return sAbsoluteDocUrl;
135360
+    return OUString();
135360
 }
135360
 
135360
 extern "C"
135360
@@ -350,6 +352,12 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
135360
     SolarMutexGuard aGuard;
135360
 
135360
     OUString aURL(getAbsoluteURL(pURL));
135360
+    if (aURL.isEmpty())
135360
+    {
135360
+        pLib->maLastExceptionMsg = "Filename to load was not provided.";
135360
+        SAL_INFO("lok", "URL for load is empty");
135360
+        return NULL;
135360
+    }
135360
 
135360
     pLib->maLastExceptionMsg.clear();
135360
 
135360
@@ -416,6 +424,12 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
135360
 
135360
     OUString sFormat = getUString(pFormat);
135360
     OUString aURL(getAbsoluteURL(sUrl));
135360
+    if (aURL.isEmpty())
135360
+    {
135360
+        gImpl->maLastExceptionMsg = "Filename to save to was not provided.";
135360
+        SAL_INFO("lok", "URL for save is empty");
135360
+        return false;
135360
+    }
135360
 
135360
     try
135360
     {
135360
-- 
135360
2.12.0
135360