Skip to content

Commit

Permalink
fix handling of 1 line multi-line quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Jul 29, 2024
1 parent ec9247a commit b359bc1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ want, and afterward, using `count`, you can use any of the names, with dashes as
needed, to count the options. One of the names is allowed to be given without
proceeding dash(es); if present the option is a positional option, and that name
will be used on the help line for its positional form. The string `++` is also
not allowed as option name due to is use in some unusual cases as an array
separator and marker on config files.
not allowed as option name due to its use as an array separator and marker on config files.

The `add_option_function<type>(...` function will typically require the template
parameter be given unless a `std::function` object with an exact match is
Expand Down
15 changes: 15 additions & 0 deletions include/CLI/impl/Config_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ inline std::vector<ConfigItem> ConfigBase::from_config(std::istream &input) cons
item.pop_back();
lineExtension = true;
}
else if (detail::hasMLString(item,keyChar))
{
//deal with the first line closing the multiline literal
item.pop_back();
item.pop_back();
item.pop_back();
if(keyChar == '\"') {
try {
item = detail::remove_escaped_characters(item);
} catch(const std::invalid_argument &iarg) {
throw CLI::ParseError(iarg.what(), CLI::ExitCodes::InvalidError);
}
}
inMLineValue=false;
}
while(inMLineValue) {
std::string l2;
if(!std::getline(input, l2)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ TEST_CASE_METHOD(TApp, "EnvOnly", "[app]") {
// reported bug #1013 on github
TEST_CASE_METHOD(TApp, "groupEnvRequired", "[app]") {
std::string str;
auto group1 = app.add_option_group("group1");
auto *group1 = app.add_option_group("group1");
put_env("CLI11_TEST_GROUP_REQUIRED", "string_abc");
group1->add_option("-f", str, "f")->envname("CLI11_TEST_GROUP_REQUIRED")->required();

Expand Down
2 changes: 1 addition & 1 deletion tests/FuzzFailTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TEST_CASE("app_roundtrip") {
CLI::FuzzApp fuzzdata2;
auto app = fuzzdata.generateApp();
auto app2 = fuzzdata2.generateApp();
int index = GENERATE(range(1, 4));
int index = GENERATE(range(1, 5));
std::string optionString, flagString;
auto parseData = loadFailureFile("round_trip_fail", index);
if(parseData.size() > 25) {
Expand Down
1 change: 1 addition & 0 deletions tests/fuzzFail/round_trip_fail4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'B"(zzzzzz!t0!!!!!--satd!!!!!!!!!--vopt0!!!!!--satd!!!]!!!!!--vopt0-b!!!b!!'B"(zzzzzz!t0!!!!!--satd!!!!!!!!!--vopt0!!!!!--satd!!!]!!!!!--vopt0-b!-bb-satd!!

0 comments on commit b359bc1

Please sign in to comment.