|
|
55db36 |
From 14c85889616de301e3a214c49fff2e6da3327d1f Mon Sep 17 00:00:00 2001
|
|
|
55db36 |
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
|
|
|
55db36 |
Date: Thu, 18 Oct 2018 20:39:23 +0100
|
|
|
55db36 |
Subject: [PATCH] keep pyuno script processing below base uri
|
|
|
55db36 |
MIME-Version: 1.0
|
|
|
55db36 |
Content-Type: text/plain; charset=UTF-8
|
|
|
55db36 |
Content-Transfer-Encoding: 8bit
|
|
|
55db36 |
|
|
|
55db36 |
Change-Id: Icc13fb7193fb1e7c50e0df286161a10b4ed636c7
|
|
|
55db36 |
Reviewed-on: https://gerrit.libreoffice.org/61970
|
|
|
55db36 |
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
|
|
|
55db36 |
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
|
|
|
55db36 |
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
|
|
|
55db36 |
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
|
|
|
55db36 |
Tested-by: Caolán McNamara <caolanm@redhat.com>
|
|
|
55db36 |
---
|
|
|
55db36 |
scripting/source/pyprov/pythonscript.py | 30 +++++++++++++++++++++++--
|
|
|
55db36 |
1 file changed, 28 insertions(+), 2 deletions(-)
|
|
|
55db36 |
|
|
|
55db36 |
diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py
|
|
|
55db36 |
index 4803d0bebc23..f5aa2173333a 100644
|
|
|
55db36 |
--- a/scripting/source/pyprov/pythonscript.py
|
|
|
55db36 |
+++ b/scripting/source/pyprov/pythonscript.py
|
|
|
55db36 |
@@ -25,6 +25,7 @@ import imp
|
|
|
55db36 |
import time
|
|
|
55db36 |
import ast
|
|
|
55db36 |
import platform
|
|
|
55db36 |
+from com.sun.star.uri.RelativeUriExcessParentSegments import RETAIN
|
|
|
55db36 |
|
|
|
55db36 |
try:
|
|
|
55db36 |
unicode
|
|
|
55db36 |
@@ -212,8 +213,33 @@ class MyUriHelper:
|
|
|
55db36 |
|
|
|
55db36 |
def scriptURI2StorageUri( self, scriptURI ):
|
|
|
55db36 |
try:
|
|
|
55db36 |
- myUri = self.m_uriRefFac.parse(scriptURI)
|
|
|
55db36 |
- ret = self.m_baseUri + "/" + myUri.getName().replace( "|", "/" )
|
|
|
55db36 |
+ # base path to the python script location
|
|
|
55db36 |
+ sBaseUri = self.m_baseUri + "/"
|
|
|
55db36 |
+ xBaseUri = self.m_uriRefFac.parse(sBaseUri)
|
|
|
55db36 |
+
|
|
|
55db36 |
+ # path to the .py file + "$functionname, arguments, etc
|
|
|
55db36 |
+ xStorageUri = self.m_uriRefFac.parse(scriptURI)
|
|
|
55db36 |
+ sStorageUri = xStorageUri.getName().replace( "|", "/" );
|
|
|
55db36 |
+
|
|
|
55db36 |
+ # path to the .py file, relative to the base
|
|
|
55db36 |
+ sFileUri = sStorageUri[0:sStorageUri.find("$")]
|
|
|
55db36 |
+ xFileUri = self.m_uriRefFac.parse(sFileUri)
|
|
|
55db36 |
+ if not xFileUri:
|
|
|
55db36 |
+ message = "pythonscript: invalid relative uri '" + sFileUri+ "'"
|
|
|
55db36 |
+ log.debug( message )
|
|
|
55db36 |
+ raise RuntimeException( message )
|
|
|
55db36 |
+
|
|
|
55db36 |
+ # absolute path to the .py file
|
|
|
55db36 |
+ xAbsScriptUri = self.m_uriRefFac.makeAbsolute(xBaseUri, xFileUri, True, RETAIN)
|
|
|
55db36 |
+ sAbsScriptUri = xAbsScriptUri.getUriReference()
|
|
|
55db36 |
+
|
|
|
55db36 |
+ # ensure py file is under the base path
|
|
|
55db36 |
+ if not sAbsScriptUri.startswith(sBaseUri):
|
|
|
55db36 |
+ message = "pythonscript: storage uri '" + sAbsScriptUri + "' not in base uri '" + self.m_baseUri + "'"
|
|
|
55db36 |
+ log.debug( message )
|
|
|
55db36 |
+ raise RuntimeException( message )
|
|
|
55db36 |
+
|
|
|
55db36 |
+ ret = sBaseUri + sStorageUri
|
|
|
55db36 |
log.debug( "converting scriptURI="+scriptURI + " to storageURI=" + ret )
|
|
|
55db36 |
return ret
|
|
|
55db36 |
except UnoException as e:
|
|
|
55db36 |
--
|
|
|
55db36 |
2.20.1
|
|
|
55db36 |
|