Duplicate field names not allowed - throw exception on load

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16902
This commit is contained in:
Roberto Fernandez Bautista 2024-02-10 17:50:53 +01:00
parent f3566a987d
commit 9f20816b24
2 changed files with 22 additions and 1 deletions

View File

@ -790,6 +790,15 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol
CurOffset() );
}
if( LIB_FIELD* existingName = aSymbol->FindField( name ) )
{
if( existingName->GetId() > MANDATORY_FIELDS )
{
THROW_PARSE_ERROR( wxString::Format( _( "Duplicate field '%s'" ), name ),
CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
}
field->SetName( name );
// Correctly set the ID based on canonical (untranslated) field name

View File

@ -669,7 +669,19 @@ void SCH_LEGACY_PLUGIN_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSymbol,
}
else
{
parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
wxString fieldName = wxEmptyString;
parseQuotedString( fieldName, aReader, line, &line, true ); // Optional.
if( fieldName.IsEmpty() )
return;
if( aSymbol->FindField( fieldName ) != nullptr )
{
SCH_PARSE_ERROR( wxString::Format( _( "Duplicate field '%s'" ), fieldName ),
aReader, line );
}
field->m_name = fieldName;
}
}