Handle updated document description format

parentheses are rarely if ever used independently, so trim the unmatched
ones regardless of whether we find the starting parenthesis in the
description

Fixes https://gitlab.com/kicad/code/kicad/issues/11403
This commit is contained in:
Seth Hillbrand 2022-04-15 11:15:46 -07:00
parent 18ac4ed842
commit be7e9d300e
1 changed files with 14 additions and 24 deletions

View File

@ -99,38 +99,28 @@ public:
idx = desc.find( wxT( "https:" ) );
if( idx >= 0 )
{
// And, sadly, it appears to have also become customary to bury the url inside
// parentheses.
if( idx >= 1 && desc.at( idx - 1 ) == '(' )
{
int nesting = 0;
while( idx < (int) desc.size() )
for( auto chit = desc.begin() + idx; chit != desc.end(); ++chit )
{
char c = desc.at( idx++ );
int ch = *chit;
if( c == '(' )
nesting++;
else if( c == ')' && --nesting < 0 )
// Break on invalid URI characters
if( ch <= 0x20 || ch >= 0x7F || ch == '"' )
break;
doc += c;
// Check for nesting parentheses, e.g. (Body style from: https://this.url/part.pdf)
if( ch == '(' )
++nesting;
else if( ch == ')' && --nesting < 0 )
break;
doc += ch;
}
desc.Replace( doc, _( "doc url" ) );
}
else
{
doc = desc.substr( (unsigned) idx );
desc = desc.substr( 0, (unsigned) idx );
desc = desc.Trim( true );
if( !desc.IsEmpty() && desc.Last() == ',' )
desc.RemoveLast( 1 );
}
}
m_html.Replace( "__NAME__", EscapeHTML( name ) );
m_html.Replace( "__DESC__", EscapeHTML( desc ) );