Browse Source

Better handling of escaped characters in STEP parser

Fixes https://gitlab.com/kicad/code/kicad/issues/9897
6.0.7
Seth Hillbrand 4 years ago
parent
commit
1b1bf8a17b
  1. 41
      libs/sexpr/sexpr_parser.cpp
  2. 2
      utils/kicad2step/pcb/3d_resolver.cpp

41
libs/sexpr/sexpr_parser.cpp

@ -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
{
closingPos = aString.find_first_of( '"', closingPos + 1 );
}
while( closingPos != std::string::npos
&& ( closingPos > 0 && aString[closingPos - 1] == '\\' ) );
auto starting_it = it;
if( closingPos != std::string::npos )
for( ; it != aString.end(); ++it )
{
auto str = std::make_unique<SEXPR_STRING>(
aString.substr( startPos, closingPos - startPos ), m_lineNumber );
std::advance( it, closingPos - startPos + 2 );
auto ch = *it;
if( ch == '\\' )
{
// Skip the next escaped character
if( ++it == aString.end() )
break;
continue;
}
return str;
if( ch == '"' )
break;
}
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
{

2
utils/kicad2step/pcb/3d_resolver.cpp

@ -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;

Loading…
Cancel
Save