Skip to content

Commit

Permalink
Escape characters bug patch(v2.9.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitherman95 authored and horenmar committed Sep 20, 2019
1 parent 3beccfb commit 2bcff9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 17 additions & 5 deletions include/internal/catch_test_spec_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ namespace Catch {
return m_testSpec;
}
void TestSpecParser::visitChar( char c ) {
if( c == ',' ) {
if( (m_mode != EscapedName) && (c == '\\') ) {
escape();
m_substring += c;
m_patternName += c;
return;
}else if((m_mode != EscapedName) && (c == ',') ) {
endMode();
addFilter();
return;
Expand Down Expand Up @@ -72,9 +77,6 @@ namespace Catch {
case '"':
startNewMode( QuotedName );
return false;
case '\\':
escape();
return true;
default:
startNewMode( Name );
return false;
Expand Down Expand Up @@ -107,13 +109,15 @@ namespace Catch {
case Tag:
return addPattern<TestSpec::TagPattern>();
case EscapedName:
return startNewMode( Name );
revertBackToLastMode();
return;
case None:
default:
return startNewMode( None );
}
}
void TestSpecParser::escape() {
saveLastMode();
m_mode = EscapedName;
m_escapeChars.push_back( m_pos );
}
Expand Down Expand Up @@ -141,6 +145,14 @@ namespace Catch {
}
}

void TestSpecParser::saveLastMode() {
lastMode = m_mode;
}

void TestSpecParser::revertBackToLastMode() {
m_mode = lastMode;
}

TestSpec parseTestSpec( std::string const& arg ) {
return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
}
Expand Down
7 changes: 5 additions & 2 deletions include/internal/catch_test_spec_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Catch {
class TestSpecParser {
enum Mode{ None, Name, QuotedName, Tag, EscapedName };
Mode m_mode = None;
Mode lastMode = None;
bool m_exclusion = false;
std::size_t m_pos = 0;
std::string m_arg;
Expand All @@ -47,7 +48,9 @@ namespace Catch {
void endMode();
void escape();
bool isControlChar( char c ) const;

void saveLastMode();
void revertBackToLastMode();

template<typename T>
void addPattern() {
std::string token = m_patternName;
Expand Down Expand Up @@ -80,4 +83,4 @@ namespace Catch {
#pragma clang diagnostic pop
#endif

#endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
#endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED

0 comments on commit 2bcff9d

Please sign in to comment.