You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2020/07/25 15:28:06 UTC

[openoffice] 02/02: Improve parsing of script URLs and detection of in-document macros therein, as per the excellent sample code in main/dbaccess/source/ext/macromigration/migrationengine.cxx method MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow().

This is an automated email from the ASF dual-hosted git repository.

damjan pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 15daf3925bdc140e28ef7cd246a147feaed4ea47
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sat Jul 25 17:23:57 2020 +0200

    Improve parsing of script URLs and detection of in-document
    macros therein, as per the excellent sample code in
    main/dbaccess/source/ext/macromigration/migrationengine.cxx
    method MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow().
    
    Patch by: me
---
 .../source/protocolhandler/scripthandler.cxx          |  9 +++++----
 main/sfx2/source/doc/objmisc.cxx                      | 19 +++++++++++++------
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/main/scripting/source/protocolhandler/scripthandler.cxx b/main/scripting/source/protocolhandler/scripthandler.cxx
index 0a1b7b0..d064fde 100644
--- a/main/scripting/source/protocolhandler/scripthandler.cxx
+++ b/main/scripting/source/protocolhandler/scripthandler.cxx
@@ -41,7 +41,6 @@
 #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
 #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
 
-#include <rtl/uri.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/frame.hxx>
 #include <sfx2/sfxdlg.hxx>
@@ -59,6 +58,7 @@
 #include "com/sun/star/uri/UriReferenceFactory.hpp"
 #include "com/sun/star/uri/XUriReferenceFactory.hpp"
 #include "com/sun/star/uri/XVndSunStarScriptUrl.hpp"
+#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
 #include "com/sun/star/beans/XPropertySet.hpp"
 
 using namespace ::com::sun::star;
@@ -161,9 +161,10 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
     {
         try
         {
-            ::rtl::OUString xStringUri = ::rtl::Uri::decode( aURL.Complete,
-                rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
-            bool bIsDocumentScript = ( xStringUri.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "document" ) ) !=-1 );
+            Reference< uri::XUriReferenceFactory > xFac( uri::UriReferenceFactory::create( m_xCtx ) );
+            Reference< uri::XVndSunStarScriptUrlReference > xScriptUri( xFac->parse( aURL.Complete ), UNO_QUERY_THROW );
+            ::rtl::OUString sLocation = xScriptUri->getParameter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "location" ) ) );
+            bool bIsDocumentScript = ( sLocation == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "document" ) ) );
 
             if ( bIsDocumentScript )
             {
diff --git a/main/sfx2/source/doc/objmisc.cxx b/main/sfx2/source/doc/objmisc.cxx
index 7f66da7..90c7c67 100644
--- a/main/sfx2/source/doc/objmisc.cxx
+++ b/main/sfx2/source/doc/objmisc.cxx
@@ -75,6 +75,9 @@
 #include <com/sun/star/task/ErrorCodeRequest.hpp>
 #include <unotools/securityoptions.hxx>
 
+#include "com/sun/star/uri/XUriReferenceFactory.hpp"
+#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp>
+
 #include <comphelper/processfactory.hxx>
 #include <comphelper/componentcontext.hxx>
 #include <comphelper/configurationhelper.hxx>
@@ -1695,16 +1698,20 @@ ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptCon
     OSL_TRACE( "in CallXScript" );
 	ErrCode nErr = ERRCODE_NONE;
 
-    bool bIsDocumentScript = ( _rScriptURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "location=document" ) ) >= 0 );
-        // TODO: we should parse the URL, and check whether there is a parameter with this name.
-        // Otherwise, we might find too much.
-    if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
-        return ERRCODE_IO_ACCESSDENIED;
-
 	bool bCaughtException = false;
     Any aException;
     try
     {
+        uno::Reference< lang::XMultiServiceFactory > xServiceManager( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW );
+        Reference< uri::XUriReferenceFactory > xFac (
+            xServiceManager->createInstance( rtl::OUString::createFromAscii(
+                "com.sun.star.uri.UriReferenceFactory") ) , UNO_QUERY_THROW );
+        Reference< uri::XVndSunStarScriptUrlReference > xScriptUri( xFac->parse( _rScriptURL ), UNO_QUERY_THROW );
+        ::rtl::OUString sLocation = xScriptUri->getParameter( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "location" ) ) );
+        bool bIsDocumentScript = ( sLocation == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "document" ) ) );
+        if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) )
+            return ERRCODE_IO_ACCESSDENIED;
+
         // obtain/create a script provider
         Reference< provider::XScriptProvider > xScriptProvider;
         Reference< provider::XScriptProviderSupplier > xSPS( _rxScriptContext, UNO_QUERY );