Skip to content

Commit

Permalink
Fix bug in TokenStream parser
Browse files Browse the repository at this point in the history
When presented with just '-' it would access the string at position [1]
  • Loading branch information
learn-more committed Sep 5, 2024
1 parent fa306fc commit 2788eb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/catch2/internal/catch_clara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions tests/SelfTest/IntrospectiveTests/Clara.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> res;
Expand Down

0 comments on commit 2788eb9

Please sign in to comment.