Require regular expressions to be explicit.
Normally this means surrounded by forward slashes, but we also still allow any regular expression in a netclass match to keep from breaking existing documents. Fixes https://gitlab.com/kicad/code/kicad/-/issues/14944
This commit is contained in:
parent
285f8a0e59
commit
d8debfa0ee
|
@ -78,17 +78,33 @@ public:
|
||||||
|
|
||||||
bool EDA_PATTERN_MATCH_REGEX::SetPattern( const wxString& aPattern )
|
bool EDA_PATTERN_MATCH_REGEX::SetPattern( const wxString& aPattern )
|
||||||
{
|
{
|
||||||
m_pattern = aPattern;
|
if( aPattern.StartsWith( "^" ) && aPattern.EndsWith( "$" ) )
|
||||||
|
{
|
||||||
|
m_pattern = aPattern;
|
||||||
|
}
|
||||||
|
else if( aPattern.StartsWith( "/" ) )
|
||||||
|
{
|
||||||
|
// Requiring a '/' on the end means they get no feedback while they type
|
||||||
|
m_pattern = aPattern.Mid( 1 );
|
||||||
|
|
||||||
|
if( m_pattern.EndsWith( "/" ) )
|
||||||
|
m_pattern = m_pattern.Left( m_pattern.length() - 1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// For now regular expressions must be explicit
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Evil and undocumented: wxRegEx::Compile calls wxLogError on error, even
|
// Evil and undocumented: wxRegEx::Compile calls wxLogError on error, even
|
||||||
// though it promises to just return false. Silence the error.
|
// though it promises to just return false. Silence the error.
|
||||||
WX_LOGLEVEL_CONTEXT ctx( wxLOG_FatalError );
|
WX_LOGLEVEL_CONTEXT ctx( wxLOG_FatalError );
|
||||||
|
|
||||||
return m_regex.Compile( aPattern, wxRE_ADVANCED );
|
return m_regex.Compile( m_pattern, wxRE_ADVANCED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EDA_PATTERN_MATCH_REGEX_EXPLICIT::SetPattern( const wxString& aPattern )
|
bool EDA_PATTERN_MATCH_REGEX_ANCHORED::SetPattern( const wxString& aPattern )
|
||||||
{
|
{
|
||||||
wxString pattern( aPattern );
|
wxString pattern( aPattern );
|
||||||
|
|
||||||
|
@ -186,7 +202,7 @@ EDA_PATTERN_MATCH::FIND_RESULT EDA_PATTERN_MATCH_WILDCARD::Find( const wxString&
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EDA_PATTERN_MATCH_WILDCARD_EXPLICIT::SetPattern( const wxString& aPattern )
|
bool EDA_PATTERN_MATCH_WILDCARD_ANCHORED::SetPattern( const wxString& aPattern )
|
||||||
{
|
{
|
||||||
m_wildcard_pattern = aPattern;
|
m_wildcard_pattern = aPattern;
|
||||||
|
|
||||||
|
@ -386,8 +402,8 @@ EDA_COMBINED_MATCHER::EDA_COMBINED_MATCHER( const wxString& aPattern,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTX_NETCLASS:
|
case CTX_NETCLASS:
|
||||||
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX_EXPLICIT>() );
|
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_REGEX_ANCHORED>() );
|
||||||
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD_EXPLICIT>() );
|
AddMatcher( aPattern, std::make_unique<EDA_PATTERN_MATCH_WILDCARD_ANCHORED>() );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTX_SIGNAL:
|
case CTX_SIGNAL:
|
||||||
|
|
|
@ -202,7 +202,7 @@ void FOOTPRINT_FILTER::FilterByFootprintFilters( const wxArrayString& aFilters )
|
||||||
|
|
||||||
for( const wxString& each_pattern : aFilters )
|
for( const wxString& each_pattern : aFilters )
|
||||||
{
|
{
|
||||||
m_footprint_filters.push_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD_EXPLICIT>() );
|
m_footprint_filters.push_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD_ANCHORED>() );
|
||||||
m_footprint_filters.back()->SetPattern( each_pattern.Lower() );
|
m_footprint_filters.back()->SetPattern( each_pattern.Lower() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class EDA_PATTERN_MATCH_REGEX_EXPLICIT : public EDA_PATTERN_MATCH_REGEX
|
class EDA_PATTERN_MATCH_REGEX_ANCHORED : public EDA_PATTERN_MATCH_REGEX
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool SetPattern( const wxString& aPattern ) override;
|
virtual bool SetPattern( const wxString& aPattern ) override;
|
||||||
|
@ -151,7 +151,7 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class EDA_PATTERN_MATCH_WILDCARD_EXPLICIT : public EDA_PATTERN_MATCH_WILDCARD
|
class EDA_PATTERN_MATCH_WILDCARD_ANCHORED : public EDA_PATTERN_MATCH_WILDCARD
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool SetPattern( const wxString& aPattern ) override;
|
virtual bool SetPattern( const wxString& aPattern ) override;
|
||||||
|
|
Loading…
Reference in New Issue