Fix LIB_ID illegal character tests.

The '/' and ':' are reserved and cannot be used in symbol or footprint
names.  They will cause the LIB_ID parser and formatter to fail.  While
it seems like they should be legal in symbol alias names, they will
trigger a symbol rescue the next time the schematic is loaded.

Use ID_SCH as in the Eagle schematic plugin rather than ID_ALIAS to
ensure symbol names do not need rescued the next time the schematic is
opened.

Remove ID_ALIAS since the rules for alias names are the same as the
rules for symbol names.  Otherwise, allowing '/' and ':' in alias names
will force a symbol rescue on the next schematic load.

Fixes lp:1795600

https://bugs.launchpad.net/kicad/+bug/1795600
This commit is contained in:
Wayne Stambaugh 2018-10-07 09:08:30 -04:00
parent ebfa7d1f7d
commit 34ea79eddb
5 changed files with 27 additions and 17 deletions

View File

@ -368,25 +368,24 @@ UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool
bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType ) bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType )
{ {
bool const colon_allowed = ( aType == ID_ALIAS ); bool const space_allowed = ( aType == ID_PCB );
bool const space_allowed = ( aType == ID_ALIAS || aType == ID_PCB ); bool const illegal_filename_chars_allowed = ( aType == ID_SCH );
bool const illegal_filename_chars_allowed = ( aType == ID_SCH || aType == ID_ALIAS );
if( aUniChar < ' ' ) if( aUniChar < ' ' )
return false; return false;
switch( aUniChar ) switch( aUniChar )
{ {
case ':':
case '/': case '/':
return false;
case '\\': case '\\':
case '<': case '<':
case '>': case '>':
case '"': case '"':
return illegal_filename_chars_allowed; return illegal_filename_chars_allowed;
case ':':
return colon_allowed;
case ' ': case ' ':
return space_allowed; return space_allowed;

View File

@ -127,7 +127,7 @@ PART_LIB* LIB_ALIAS::GetLib()
void LIB_ALIAS::SetName( const wxString& aName ) void LIB_ALIAS::SetName( const wxString& aName )
{ {
name = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_ALIAS ); name = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
} }

View File

@ -2619,13 +2619,7 @@ void SCH_EAGLE_PLUGIN::addImplicitConnections( SCH_COMPONENT* aComponent,
wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName ) wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName )
{ {
wxString ret = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_ALIAS ); wxString ret = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
for( auto ch = ret.begin(); ch != ret.end(); ++ch )
{
if( *ch == '/' )
*ch = '_';
}
return ret; return ret;
} }

View File

@ -2465,7 +2465,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs()
SCH_PARSE_ERROR( "$CMP command expected", reader, line ); SCH_PARSE_ERROR( "$CMP command expected", reader, line );
parseUnquotedString( aliasName, reader, line, &line ); // Alias name. parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_ALIAS ); aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH );
LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName ); LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
if( it == m_aliases.end() ) if( it == m_aliases.end() )

View File

@ -53,7 +53,7 @@ class LIB_ID
public: public:
///> Types of library identifiers ///> Types of library identifiers
enum LIB_ID_TYPE { ID_SCH, ID_ALIAS, ID_PCB }; enum LIB_ID_TYPE { ID_SCH, ID_PCB };
LIB_ID() {} LIB_ID() {}
@ -234,7 +234,24 @@ public:
protected: protected:
/** /**
* Tests whether a unicode character is a legal LIB_ID item name character * Tests whether a unicode character is a legal LIB_ID item name character.
*
* The criteria for legal LIB_ID character is as follows:
* - For both symbol and footprint names, neither '/' or ':' are legal. They are
* reserved characters used by #LIB_ID::Parse.
* - Spaces are allowed in footprint names as they are a legal filename character
* on all operating systems.
* - Spaces are not allowed in symbol names since symbol names are not quoted in the
* schematic or symbol library file formats.
* - Spaces are allowed in footprint library nicknames as they are quoted in the
* footprint library table file format.
* - Spaces are not allowed in symbol library nicknames since they are not quoted in
* the symbol library file format.
* - Illegal file name characters are not allowed in footprint names since the file
* name is the footprint name.
* - Illegal file name characters except '/' are allowed in symbol names since the
* name is not the file name.
*
* *
* @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use * @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use
* a variable length coding value. * a variable length coding value.