Fix arg parsing in ExecuteFile.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15326
This commit is contained in:
Jeff Young 2023-09-23 14:32:44 +01:00
parent 1fd3f4e375
commit 0f94b467ba
1 changed files with 72 additions and 12 deletions

View File

@ -38,6 +38,7 @@
#include <gestfich.h>
#include <string_utils.h>
#include <launch_ext.h>
#include "wx/tokenzr.h"
void QuoteString( wxString& string )
{
@ -116,22 +117,78 @@ wxString FindKicadFile( const wxString& shortname )
int ExecuteFile( const wxString& aEditorName, const wxString& aFileName, wxProcess *aCallback )
{
wxString fullEditorName;
wxString param;
wxString fullEditorName;
std::vector<wxString> params;
#ifdef __UNIX__
int space = aEditorName.Find( ' ' );
wxString param;
bool inSingleQuotes = false;
bool inDoubleQuotes = false;
if( space > 0 && !aEditorName.Contains( "\"" ) && !aEditorName.Contains( "\'" ) )
auto pushParam =
[&]()
{
if( !param.IsEmpty() )
{
params.push_back( param );
param.clear();
}
};
for( wxUniChar ch : aEditorName )
{
fullEditorName = FindKicadFile( aEditorName.Mid( 0, space ) );
param = aEditorName.Mid( space + 1 );
if( inSingleQuotes )
{
if( ch == '\'' )
{
pushParam();
inSingleQuotes = false;
continue;
}
else
{
param += ch;
}
}
else if( inDoubleQuotes )
{
if( ch == '"' )
{
pushParam();
inDoubleQuotes = false;
}
else
{
param += ch;
}
}
else if( ch == '\'' )
{
pushParam();
inSingleQuotes = true;
}
else if( ch == '"' )
{
pushParam();
inDoubleQuotes = true;
}
else if( ch == ' ' )
{
pushParam();
}
else
{
param += ch;
}
}
else
pushParam();
fullEditorName = FindKicadFile( params[0] );
params.erase( params.begin() );
#else
fullEditorName = FindKicadFile( aEditorName );
#endif
{
fullEditorName = FindKicadFile( aEditorName );
}
if( wxFileExists( fullEditorName ) )
{
@ -140,8 +197,11 @@ int ExecuteFile( const wxString& aEditorName, const wxString& aFileName, wxProce
args[i++] = fullEditorName.wc_str();
if( !param.IsEmpty() )
args[i++] = param.wc_str();
if( !params.empty() )
{
for( const wxString& p : params )
args[i++] = p.wc_str();
}
if( !aFileName.IsEmpty() )
args[i++] = aFileName.wc_str();