Commit 020a21afc65fe843efca5b2f74e3d5b502425f76

Authored by Philip Top
Committed by GitHub
1 parent c692be41

Fix an issue where an error was generated if just a file name was supplied to th…

…e split_program_name parsing (#740)
include/CLI/Validators.hpp
@@ -1163,7 +1163,7 @@ inline std::pair<std::string, std::string> split_program_name(std::string comman @@ -1163,7 +1163,7 @@ inline std::pair<std::string, std::string> split_program_name(std::string comman
1163 } 1163 }
1164 1164
1165 // strip the program name 1165 // strip the program name
1166 - vals.second = (esp != std::string::npos) ? commandline.substr(esp + 1) : std::string{}; 1166 + vals.second = (esp < commandline.length() - 1) ? commandline.substr(esp + 1) : std::string{};
1167 ltrim(vals.second); 1167 ltrim(vals.second);
1168 return vals; 1168 return vals;
1169 } 1169 }
tests/StringParseTest.cpp
@@ -89,6 +89,15 @@ TEST_CASE_METHOD(TApp, &quot;ProgNameWithSpace&quot;, &quot;[stringparse]&quot;) { @@ -89,6 +89,15 @@ TEST_CASE_METHOD(TApp, &quot;ProgNameWithSpace&quot;, &quot;[stringparse]&quot;) {
89 CHECK(app.get_name() == "Foo Bar"); 89 CHECK(app.get_name() == "Foo Bar");
90 } 90 }
91 91
  92 +// From GitHub issue #739 https://github.com/CLIUtils/CLI11/issues/739
  93 +TEST_CASE_METHOD(TApp, "ProgNameOnly", "[stringparse]") {
  94 +
  95 + app.add_flag("--foo");
  96 + CHECK_NOTHROW(app.parse("\"C:\\example.exe\"", true));
  97 +
  98 + CHECK(app.get_name() == "C:\\example.exe");
  99 +}
  100 +
92 TEST_CASE_METHOD(TApp, "ProgNameWithSpaceEmbeddedQuote", "[stringparse]") { 101 TEST_CASE_METHOD(TApp, "ProgNameWithSpaceEmbeddedQuote", "[stringparse]") {
93 102
94 app.add_flag("--foo"); 103 app.add_flag("--foo");