From 327153471ae38abe90463f6272e00aaa996c5ba3 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 19 Jun 2020 11:32:00 +0100 Subject: tdf#121384 don't leave a bare trailing : in PYTHONPATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and don't insert any empty path entries if that situation was to arise Change-Id: I8d8183485f457c3e4385181fee07390c4bfef603 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96713 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- pyuno/source/loader/pyuno_loader.cxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'pyuno') diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index 8556dfdde11f..07dc748235f9 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -140,6 +140,7 @@ static void setPythonHome ( const OUString & pythonHome ) static void prependPythonPath( const OUString & pythonPathBootstrap ) { OUStringBuffer bufPYTHONPATH( 256 ); + bool bAppendSep = false; sal_Int32 nIndex = 0; while( true ) { @@ -155,15 +156,24 @@ static void prependPythonPath( const OUString & pythonPathBootstrap ) } OUString systemPath; osl_getSystemPathFromFileURL( fileUrl.pData, &(systemPath.pData) ); - bufPYTHONPATH.append( systemPath ); - bufPYTHONPATH.append( static_cast(SAL_PATHSEPARATOR) ); + if (!systemPath.isEmpty()) + { + if (bAppendSep) + bufPYTHONPATH.append(static_cast(SAL_PATHSEPARATOR)); + bufPYTHONPATH.append(systemPath); + bAppendSep = true; + } if( nNew == -1 ) break; nIndex = nNew + 1; } const char * oldEnv = getenv( "PYTHONPATH"); if( oldEnv ) + { + if (bAppendSep) + bufPYTHONPATH.append( static_cast(SAL_PATHSEPARATOR) ); bufPYTHONPATH.append( OUString(oldEnv, strlen(oldEnv), osl_getThreadTextEncoding()) ); + } OUString envVar("PYTHONPATH"); OUString envValue(bufPYTHONPATH.makeStringAndClear()); -- cgit v1.2.3