Handle backslash-escaped quotes in libeval.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15786
This commit is contained in:
Jeff Young 2023-09-30 14:54:25 +01:00
parent b2bf28f559
commit 9805aca5a0
3 changed files with 38 additions and 12 deletions

View File

@ -201,6 +201,24 @@ wxString UCODE::Dump() const
};
wxString TOKENIZER::GetString()
{
wxString rv;
while( m_pos < m_str.length() && m_str[ m_pos ] != '\'' )
{
if( m_str[ m_pos ] == '\\' && m_pos + 1 < m_str.length() && m_str[ m_pos + 1 ] == '\'' )
m_pos++;
rv.append( 1, m_str[ m_pos++ ] );
}
m_pos++;
return rv;
}
wxString TOKENIZER::GetChars( const std::function<bool( wxUniChar )>& cond ) const
{
wxString rv;
@ -383,12 +401,9 @@ T_TOKEN COMPILER::getToken()
bool COMPILER::lexString( T_TOKEN& aToken )
{
wxString str = m_tokenizer.GetChars( []( int c ) -> bool { return c != '\''; } );
aToken.token = G_STRING;
aToken.value.str = new wxString( str );
aToken.value.str = new wxString( m_tokenizer.GetString() );
m_tokenizer.NextChar( str.length() + 1 );
m_lexerState = LS_DEFAULT;
return true;
}

View File

@ -474,6 +474,8 @@ public:
return m_pos;
}
wxString GetString();
wxString GetChars( const std::function<bool( wxUniChar )>& cond ) const;
bool MatchAhead( const wxString& match,

View File

@ -229,13 +229,21 @@ void DRC_ENGINE::loadImplicitRules()
auto makeNetclassRules =
[&]( const std::shared_ptr<NETCLASS>& nc, bool isDefault )
{
wxString ncName = nc->GetName();
wxString expr;
wxString ncName = nc->GetName();
wxString friendlyName;
wxString* shownName = &ncName;
wxString expr;
if( ncName.Replace( "'", "\\'" ) )
{
friendlyName = nc->GetName();
shownName = &friendlyName;
}
if( nc->GetClearance() || nc->GetTrackWidth() )
{
std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), ncName );
netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), *shownName );
netclassRule->m_Implicit = true;
expr = wxString::Format( wxT( "A.NetClass == '%s'" ), ncName );
@ -262,7 +270,7 @@ void DRC_ENGINE::loadImplicitRules()
{
std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
ncName );
*shownName );
netclassRule->m_Implicit = true;
expr = wxString::Format( wxT( "A.NetClass == '%s' && A.inDiffPair('*')" ),
@ -280,7 +288,7 @@ void DRC_ENGINE::loadImplicitRules()
{
std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
ncName );
*shownName );
netclassRule->m_Implicit = true;
expr = wxString::Format( wxT( "A.NetClass == '%s'" ), ncName );
@ -297,7 +305,7 @@ void DRC_ENGINE::loadImplicitRules()
{
netclassRule = std::make_shared<DRC_RULE>();
netclassRule->m_Name = wxString::Format( _( "netclass '%s' (diff pair)" ),
ncName );
*shownName );
netclassRule->m_Implicit = true;
expr = wxString::Format( wxT( "A.NetClass == '%s' && AB.isCoupledDiffPair()" ),
@ -314,7 +322,7 @@ void DRC_ENGINE::loadImplicitRules()
if( nc->GetViaDiameter() || nc->GetViaDrill() )
{
std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), ncName );
netclassRule->m_Name = wxString::Format( _( "netclass '%s'" ), *shownName );
netclassRule->m_Implicit = true;
expr = wxString::Format( wxT( "A.NetClass == '%s' && A.Via_Type != 'Micro'" ),
@ -342,7 +350,8 @@ void DRC_ENGINE::loadImplicitRules()
if( nc->GetuViaDiameter() || nc->GetuViaDrill() )
{
std::shared_ptr<DRC_RULE> netclassRule = std::make_shared<DRC_RULE>();
netclassRule->m_Name = wxString::Format( _( "netclass '%s' (uvia)" ), ncName );
netclassRule->m_Name = wxString::Format( _( "netclass '%s' (uvia)" ),
*shownName );
netclassRule->m_Implicit = true;
expr = wxString::Format( wxT( "A.NetClass == '%s' && A.Via_Type == 'Micro'" ),