diff --git a/src/catch2/internal/catch_clara.cpp b/src/catch2/internal/catch_clara.cpp index c76089eea1..f9dd913857 100644 --- a/src/catch2/internal/catch_clara.cpp +++ b/src/catch2/internal/catch_clara.cpp @@ -76,7 +76,7 @@ namespace Catch { { TokenType::Argument, next.substr( delimiterPos + 1, next.size() ) } ); } else { - if ( next[1] != '-' && next.size() > 2 ) { + if ( next.size() > 1 && next[1] != '-' && next.size() > 2 ) { // Combined short args, e.g. "-ab" for "-a -b" for ( size_t i = 1; i < next.size(); ++i ) { m_tokenBuffer.push_back( diff --git a/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp b/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp index 14ba433dad..1b0c531158 100644 --- a/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp @@ -51,6 +51,16 @@ TEST_CASE("Clara::Arg supports single-arg parse the way Opt does", "[clara][arg] REQUIRE(name == "foo"); } +TEST_CASE("Clara::Arg does not crash on incomplete input", "[clara][arg][compilation]") { + std::string name; + auto p = Catch::Clara::Arg(name, "-"); + + CHECK(name.empty()); + + p.parse( Catch::Clara::Args{ "UnitTest", "-" } ); + CHECK( name.empty() ); +} + TEST_CASE("Clara::Opt supports accept-many lambdas", "[clara][opt]") { using namespace Catch::Clara; std::vector res;