mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Also limit the number of search terms (as well as their length)
Fixes https://gitlab.com/kicad/code/kicad/-/issues/19464
This commit is contained in:
parent
e7a79216ab
commit
577c1dd332
@ -488,8 +488,8 @@ int EDA_COMBINED_MATCHER::ScoreTerms( std::vector<SEARCH_TERM>& aWeightedTerms )
|
|||||||
|
|
||||||
// Don't cause KiCad to hang if someone accidentally pastes the PCB or schematic
|
// Don't cause KiCad to hang if someone accidentally pastes the PCB or schematic
|
||||||
// into the search box.
|
// into the search box.
|
||||||
if( term.Text.Length() > 5000 )
|
if( term.Text.Length() > 1000 )
|
||||||
term.Text = term.Text.Left( 5000 );
|
term.Text = term.Text.Left( 1000 );
|
||||||
|
|
||||||
term.Normalized = true;
|
term.Normalized = true;
|
||||||
}
|
}
|
||||||
|
@ -285,17 +285,21 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
|
|||||||
|
|
||||||
m_tree.ResetScore();
|
m_tree.ResetScore();
|
||||||
|
|
||||||
wxStringTokenizer tokenizer( aSearch );
|
// Don't cause KiCad to hang if someone accidentally pastes the PCB or schematic into
|
||||||
bool firstTerm = true;
|
// the search box.
|
||||||
|
constexpr int MAX_TERMS = 100;
|
||||||
|
|
||||||
while( tokenizer.HasMoreTokens() )
|
wxStringTokenizer tokenizer( aSearch );
|
||||||
|
int termCount = 0;
|
||||||
|
|
||||||
|
while( tokenizer.HasMoreTokens() && termCount < MAX_TERMS )
|
||||||
{
|
{
|
||||||
// First search for the full token, in case it appears in a search string
|
// First search for the full token, in case it appears in a search string
|
||||||
wxString term = tokenizer.GetNextToken().Lower();
|
wxString term = tokenizer.GetNextToken().Lower();
|
||||||
EDA_COMBINED_MATCHER termMatcher( term, CTX_LIBITEM );
|
EDA_COMBINED_MATCHER termMatcher( term, CTX_LIBITEM );
|
||||||
|
|
||||||
m_tree.UpdateScore( &termMatcher, wxEmptyString, m_filter );
|
m_tree.UpdateScore( &termMatcher, wxEmptyString, m_filter );
|
||||||
firstTerm = false;
|
termCount++;
|
||||||
|
|
||||||
if( term.Contains( ":" ) )
|
if( term.Contains( ":" ) )
|
||||||
{
|
{
|
||||||
@ -308,7 +312,7 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( firstTerm )
|
if( termCount == 0 )
|
||||||
{
|
{
|
||||||
// No terms processed; just run the filter
|
// No terms processed; just run the filter
|
||||||
m_tree.UpdateScore( nullptr, wxEmptyString, m_filter );
|
m_tree.UpdateScore( nullptr, wxEmptyString, m_filter );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user