1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-30 20:53:52 +00:00

Fix an issue where an error was generated if just a file name was supplied to the split_program_name parsing (#740)

This commit is contained in:
Philip Top 2022-06-05 19:36:30 -07:00 committed by GitHub
parent c692be41cf
commit 020a21afc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1163,7 +1163,7 @@ inline std::pair<std::string, std::string> split_program_name(std::string comman
}
// strip the program name
vals.second = (esp != std::string::npos) ? commandline.substr(esp + 1) : std::string{};
vals.second = (esp < commandline.length() - 1) ? commandline.substr(esp + 1) : std::string{};
ltrim(vals.second);
return vals;
}

View File

@ -89,6 +89,15 @@ TEST_CASE_METHOD(TApp, "ProgNameWithSpace", "[stringparse]") {
CHECK(app.get_name() == "Foo Bar");
}
// From GitHub issue #739 https://github.com/CLIUtils/CLI11/issues/739
TEST_CASE_METHOD(TApp, "ProgNameOnly", "[stringparse]") {
app.add_flag("--foo");
CHECK_NOTHROW(app.parse("\"C:\\example.exe\"", true));
CHECK(app.get_name() == "C:\\example.exe");
}
TEST_CASE_METHOD(TApp, "ProgNameWithSpaceEmbeddedQuote", "[stringparse]") {
app.add_flag("--foo");