Legacy libraries: De-duplicate field names on load

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16902
This commit is contained in:
Roberto Fernandez Bautista 2024-02-22 21:31:57 +01:00
parent 420413969e
commit 07ab18a1e6
1 changed files with 14 additions and 1 deletions

View File

@ -670,7 +670,20 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSym
}
else
{
parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
wxString fieldName = wxEmptyString;
parseQuotedString( fieldName, aReader, line, &line, true ); // Optional.
if( fieldName.IsEmpty() )
return;
wxString candidateFieldName = fieldName;
int suffix = 0;
//Deduplicate field name
while( aSymbol->FindField( candidateFieldName ) != nullptr )
candidateFieldName = wxString::Format( "%s_%d", fieldName, ++suffix );
field->m_name = candidateFieldName;
}
}