Better handling of escaped characters in STEP parser
Fixes https://gitlab.com/kicad/code/kicad/issues/9897
This commit is contained in:
parent
01068e0d41
commit
1b1bf8a17b
|
@ -122,29 +122,36 @@ namespace SEXPR
|
||||||
}
|
}
|
||||||
else if( *it == '"' )
|
else if( *it == '"' )
|
||||||
{
|
{
|
||||||
size_t startPos = std::distance(aString.begin(), it) + 1;
|
++it;
|
||||||
size_t closingPos = startPos > 0 ? startPos - 1 : startPos;
|
|
||||||
|
|
||||||
// find the closing quote character, be sure it is not escaped
|
auto starting_it = it;
|
||||||
do
|
|
||||||
|
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 )
|
if( it == aString.end() )
|
||||||
{
|
|
||||||
auto str = std::make_unique<SEXPR_STRING>(
|
|
||||||
aString.substr( startPos, closingPos - startPos ), m_lineNumber );
|
|
||||||
std::advance( it, closingPos - startPos + 2 );
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw PARSE_EXCEPTION("missing closing quote");
|
throw PARSE_EXCEPTION("missing closing quote");
|
||||||
}
|
|
||||||
|
auto str = std::make_unique<SEXPR_STRING>( std::string( starting_it, it ),
|
||||||
|
m_lineNumber );
|
||||||
|
|
||||||
|
++it;
|
||||||
|
return str;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -184,7 +184,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName,
|
||||||
// been checked. This case accounts for partial paths which do not contain ${KIPRJMOD}.
|
// 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
|
// 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}.
|
// 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, "" );
|
tmpFN.Assign( m_Paths.begin()->m_Pathexp, "" );
|
||||||
wxString fullPath = tmpFN.GetPathWithSep() + tname;
|
wxString fullPath = tmpFN.GetPathWithSep() + tname;
|
||||||
|
|
Loading…
Reference in New Issue