From 43e501ca56ca6d0c45b0695c8ebdc5fda757a867 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Sun, 5 Jun 2022 06:37:16 -0700 Subject: [PATCH] Fix an issue where an error was generated if just a file name was supplied to the split_program_name parsing --- include/CLI/Validators.hpp | 2 +- tests/StringParseTest.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/CLI/Validators.hpp b/include/CLI/Validators.hpp index 1281997ae..a03cbe5e3 100644 --- a/include/CLI/Validators.hpp +++ b/include/CLI/Validators.hpp @@ -1163,7 +1163,7 @@ inline std::pair 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; } diff --git a/tests/StringParseTest.cpp b/tests/StringParseTest.cpp index 48a173530..88b42a42d 100644 --- a/tests/StringParseTest.cpp +++ b/tests/StringParseTest.cpp @@ -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");