Library Field editor: validate alias name before changing it

When LIB_ALIAS is renamed, it validates the new name. In case the name
typed in the field edit dialog is invalid, there was a discrepancy
between the name used further in the code and the actual alias name.

Fixes: lp:1765375
* https://bugs.launchpad.net/kicad/+bug/1765375
This commit is contained in:
Maciej Suminski 2018-04-19 14:45:36 +02:00
parent a695c995c7
commit 2865084ce8
3 changed files with 15 additions and 18 deletions

View File

@ -116,11 +116,18 @@ PART_LIB* LIB_ALIAS::GetLib()
return shared->GetLib();
}
// Helper function to replace illegal chars in symbol names
// they are same as illegal filename chars, but the ':' is allowed
// only because it is used to create symbol names in lib cache
static void replaceIllegalSymbolNameChars( wxString& aName )
void LIB_ALIAS::SetName( const wxString& aName )
{
name = aName;
ValidateName( name );
}
void LIB_ALIAS::ValidateName( wxString& aName )
{
// they are same as illegal filename chars, but the ':' is allowed
// only because it is used to create symbol names in lib cache
static const wxString illegalSymbolNameChars( "\\/\"<>|" );
for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
@ -130,12 +137,6 @@ static void replaceIllegalSymbolNameChars( wxString& aName )
}
}
void LIB_ALIAS::SetName( const wxString& aName )
{
name = aName;
replaceIllegalSymbolNameChars( name );
}
bool LIB_ALIAS::operator==( const wxChar* aName ) const
{

View File

@ -119,6 +119,9 @@ public:
void SetName( const wxString& aName );
///> Helper function to replace illegal chars in symbol names
static void ValidateName( wxString& aName );
void SetDescription( const wxString& aDescription )
{
description = aDescription;

View File

@ -42,7 +42,6 @@
void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
{
wxString newFieldValue;
wxString title;
wxString caption;
if( aField == NULL )
@ -54,16 +53,9 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
// Editing the component value field is equivalent to creating a new component based
// on the current component. Set the dialog message to inform the user.
if( aField->GetId() == VALUE )
{
caption = _( "Component Name" );
title = _( "Enter a name to create a new component based on this one." );
}
else
{
caption.Printf( _( "Edit Field %s" ), GetChars( aField->GetName() ) );
title.Printf( _( "Enter a new value for the %s field." ),
GetChars( aField->GetName().Lower() ) );
}
DIALOG_LIB_EDIT_ONE_FIELD dlg( this, caption, aField );
@ -73,6 +65,7 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
return;
newFieldValue = dlg.GetText();
LIB_ALIAS::ValidateName( newFieldValue );
wxString oldFieldValue = aField->GetFullText( m_unit );
bool renamed = aField->GetId() == VALUE && newFieldValue != oldFieldValue;