Better handling of escaped characters in STEP parser

Fixes https://gitlab.com/kicad/code/kicad/issues/9897
This commit is contained in:
Seth Hillbrand 2021-12-08 15:50:33 -08:00
parent 01068e0d41
commit 1b1bf8a17b
2 changed files with 26 additions and 19 deletions

View File

@ -122,29 +122,36 @@ namespace SEXPR
}
else if( *it == '"' )
{
size_t startPos = std::distance(aString.begin(), it) + 1;
size_t closingPos = startPos > 0 ? startPos - 1 : startPos;
++it;
// find the closing quote character, be sure it is not escaped
do
auto starting_it = it;
for( ; it != aString.end(); ++it )
{
closingPos = aString.find_first_of( '"', closingPos + 1 );
auto ch = *it;
if( ch == '\\' )
{
// Skip the next escaped character
if( ++it == aString.end() )
break;
continue;
}
if( ch == '"' )
break;
}
while( closingPos != std::string::npos
&& ( closingPos > 0 && aString[closingPos - 1] == '\\' ) );
if( closingPos != std::string::npos )
{
auto str = std::make_unique<SEXPR_STRING>(
aString.substr( startPos, closingPos - startPos ), m_lineNumber );
std::advance( it, closingPos - startPos + 2 );
return str;
}
else
{
if( it == aString.end() )
throw PARSE_EXCEPTION("missing closing quote");
}
auto str = std::make_unique<SEXPR_STRING>( std::string( starting_it, it ),
m_lineNumber );
++it;
return str;
}
else
{

View File

@ -184,7 +184,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName,
// been checked. This case accounts for partial paths which do not contain ${KIPRJMOD}.
// This check is performed before checking the path relative to ${KICAD6_3DMODEL_DIR} so that
// users can potentially override a model within ${KICAD6_3DMODEL_DIR}.
if( !m_Paths.begin()->m_Pathexp.empty() && !tname.StartsWith( ":" ) )
if( !m_Paths.empty() && !m_Paths.begin()->m_Pathexp.empty() && !tname.StartsWith( ":" ) )
{
tmpFN.Assign( m_Paths.begin()->m_Pathexp, "" );
wxString fullPath = tmpFN.GetPathWithSep() + tname;