mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 00:21:25 +00:00
eeschema, DIALOG_SHEET_PROPERTIES: add test for valid sheet filename
Fixes https://gitlab.com/kicad/code/kicad/-/issues/18981
This commit is contained in:
parent
8dda9b37fa
commit
82ff2c0e0f
@ -45,6 +45,34 @@
|
||||
static const char illegalFileNameChars[] = "\\/:\"<>|*?";
|
||||
|
||||
|
||||
// Checks if a full filename is valid, i.e. does not contains illegal chars
|
||||
bool IsFullFileNameValid( const wxString& aFullFilename )
|
||||
{
|
||||
|
||||
// Test for forbidden chars in aFullFilename.
|
||||
// '\'and '/' are allowed here because aFullFilename can be a full path, and
|
||||
// ':' is allowed on Windows as second char in string.
|
||||
// So remove allowed separators from string to test
|
||||
wxString filtered_fullpath = aFullFilename;
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
// On MSW, the list returned by wxFileName::GetForbiddenChars() contains separators
|
||||
// '\'and '/'
|
||||
filtered_fullpath.Replace( "/", "_" );
|
||||
filtered_fullpath.Replace( "\\", "_" );
|
||||
|
||||
// A disk identifier is allowed, and therefore remove its separator
|
||||
if( filtered_fullpath.Length() > 1 && filtered_fullpath[1] == ':' )
|
||||
filtered_fullpath[1] = ' ';
|
||||
#endif
|
||||
|
||||
if( wxString::npos != filtered_fullpath.find_first_of( wxFileName::GetForbiddenChars() ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
wxString ConvertToNewOverbarNotation( const wxString& aOldStr )
|
||||
{
|
||||
wxString newStr;
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include <trace_helpers.h>
|
||||
#include "panel_eeschema_color_settings.h"
|
||||
#include "wx/dcclient.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_SHEET* aSheet,
|
||||
bool* aIsUndoable, bool* aClearAnnotationNewItems,
|
||||
@ -280,7 +281,15 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataFromWindow()
|
||||
// but unedited data from existing files can be bad.)
|
||||
sheetFileName = EnsureFileExtension( sheetFileName, FILEEXT::KiCadSchematicFileExtension );
|
||||
|
||||
// Ensure sheetFileName is legal
|
||||
if( !IsFullFileNameValid( sheetFileName ) )
|
||||
{
|
||||
DisplayError( this, _( "A sheet must have a valid file name." ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
wxFileName fn( sheetFileName );
|
||||
|
||||
wxString newRelativeFilename = fn.GetFullPath();
|
||||
|
||||
// Inside Eeschema, filenames are stored using unix notation
|
||||
|
@ -231,6 +231,13 @@ KICOMMON_API int GetTrailingInt( const wxString& aStr );
|
||||
*/
|
||||
KICOMMON_API wxString GetIllegalFileNameWxChars();
|
||||
|
||||
/**
|
||||
* Checks if a full filename is valid, i.e. does not contains illegal chars
|
||||
* path separators are allowed
|
||||
* @return true if OK.
|
||||
*/
|
||||
KICOMMON_API bool IsFullFileNameValid( const wxString& aFullFilename );
|
||||
|
||||
/**
|
||||
* Checks \a aName for illegal file name characters.
|
||||
*
|
||||
@ -392,7 +399,7 @@ KICOMMON_API std::string FormatDouble2Str( double aValue );
|
||||
|
||||
/**
|
||||
* Convert an expected UTF8 encoded std::string to a wxString.
|
||||
* If fails, tray to convert using current locale
|
||||
* If fails, try to convert using current locale
|
||||
* If still fails, return the initial string (can be already a converted string)
|
||||
*/
|
||||
KICOMMON_API wxString From_UTF8( const std::string& aString );
|
||||
|
Loading…
Reference in New Issue
Block a user