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 39c38fb386
commit 876232aa7a
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 const colon_allowed = ( aType == ID_ALIAS );
bool const space_allowed = ( aType == ID_ALIAS || aType == ID_PCB );
bool const illegal_filename_chars_allowed = ( aType == ID_SCH || aType == ID_ALIAS );
bool const space_allowed = ( aType == ID_PCB );
bool const illegal_filename_chars_allowed = ( aType == ID_SCH );
if( aUniChar < ' ' )
return false;
switch( aUniChar )
{
case ':':
case '/':
return false;
case '\\':
case '<':
case '>':
case '"':
return illegal_filename_chars_allowed;
case ':':
return colon_allowed;
case ' ':
return space_allowed;

View File

@ -119,7 +119,7 @@ PART_LIB* LIB_ALIAS::GetLib()
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

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

View File

@ -2421,7 +2421,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs()
SCH_PARSE_ERROR( "$CMP command expected", reader, line );
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 );
if( it == m_aliases.end() )

View File

@ -53,7 +53,7 @@ class LIB_ID
public:
///> Types of library identifiers
enum LIB_ID_TYPE { ID_SCH, ID_ALIAS, ID_PCB };
enum LIB_ID_TYPE { ID_SCH, ID_PCB };
LIB_ID() {}
@ -234,7 +234,24 @@ public:
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
* a variable length coding value.