CLI: Sanitize filename when exporting symbol as svg

When using symbol names as filenames, invalid characters and
characters that might be mis-interpreted (e.g. '/') have to be
removed from the name to prevent unexpected behavior.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/15751
This commit is contained in:
Matthias Breithaupt 2023-09-27 14:24:32 +00:00 committed by Mark Roszko
parent 6b12a12b3e
commit be9e4c79ee
1 changed files with 11 additions and 4 deletions

View File

@ -579,14 +579,23 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob,
{ {
wxString filename; wxString filename;
wxFileName fn; wxFileName fn;
size_t forbidden_char;
fn.SetPath( aSvgJob->m_outputDirectory ); fn.SetPath( aSvgJob->m_outputDirectory );
fn.SetExt( SVGFileExtension ); fn.SetExt( SVGFileExtension );
filename = symbol->GetName().Lower();
while( wxString::npos
!= ( forbidden_char = filename.find_first_of(
wxFileName::GetForbiddenChars( wxPATH_DOS ) ) ) )
{
filename = filename.replace( forbidden_char, 1, wxS( '_' ) );
}
//simplify the name if its single unit //simplify the name if its single unit
if( symbol->IsMulti() ) if( symbol->IsMulti() )
{ {
filename = wxString::Format( "%s_%d", symbol->GetName().Lower(), unit ); filename += wxString::Format( "_%d", unit );
if( convert == 2 ) if( convert == 2 )
filename += wxS( "_demorgan" ); filename += wxS( "_demorgan" );
@ -598,8 +607,6 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob,
} }
else else
{ {
filename = symbol->GetName().Lower();
if( convert == 2 ) if( convert == 2 )
filename += wxS( "_demorgan" ); filename += wxS( "_demorgan" );
@ -912,4 +919,4 @@ DS_PROXY_VIEW_ITEM* EESCHEMA_JOBS_HANDLER::getDrawingSheetProxyView( SCHEMATIC*
drawingSheet->SetSheetPath( "" ); drawingSheet->SetSheetPath( "" );
return drawingSheet; return drawingSheet;
} }