From 2bcff9dd3581708d50734d3f55949146e5ba0162 Mon Sep 17 00:00:00 2001 From: amitherman95 Date: Sat, 14 Sep 2019 12:38:47 +0300 Subject: [PATCH] Escape characters bug patch(v2.9.2) --- include/internal/catch_test_spec_parser.cpp | 22 ++++++++++++++++----- include/internal/catch_test_spec_parser.h | 7 +++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_test_spec_parser.cpp b/include/internal/catch_test_spec_parser.cpp index a910ac7e..5cbbdeb7 100644 --- a/include/internal/catch_test_spec_parser.cpp +++ b/include/internal/catch_test_spec_parser.cpp @@ -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; @@ -72,9 +77,6 @@ namespace Catch { case '"': startNewMode( QuotedName ); return false; - case '\\': - escape(); - return true; default: startNewMode( Name ); return false; @@ -107,13 +109,15 @@ namespace Catch { case Tag: return addPattern(); 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 ); } @@ -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(); } diff --git a/include/internal/catch_test_spec_parser.h b/include/internal/catch_test_spec_parser.h index 5b02bf6d..778da134 100644 --- a/include/internal/catch_test_spec_parser.h +++ b/include/internal/catch_test_spec_parser.h @@ -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; @@ -47,7 +48,9 @@ namespace Catch { void endMode(); void escape(); bool isControlChar( char c ) const; - + void saveLastMode(); + void revertBackToLastMode(); + template void addPattern() { std::string token = m_patternName; @@ -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 \ No newline at end of file