From b359bc177811ff9462976b7b3950d03223ef1bd0 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Mon, 29 Jul 2024 08:36:26 -0700 Subject: [PATCH] fix handling of 1 line multi-line quoted strings --- README.md | 3 +-- include/CLI/impl/Config_inl.hpp | 15 +++++++++++++++ tests/AppTest.cpp | 2 +- tests/FuzzFailTest.cpp | 2 +- tests/fuzzFail/round_trip_fail4 | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/fuzzFail/round_trip_fail4 diff --git a/README.md b/README.md index bd32539e8..e6ba23c8d 100644 --- a/README.md +++ b/README.md @@ -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(...` function will typically require the template parameter be given unless a `std::function` object with an exact match is diff --git a/include/CLI/impl/Config_inl.hpp b/include/CLI/impl/Config_inl.hpp index 61d7f3a71..56b983656 100644 --- a/include/CLI/impl/Config_inl.hpp +++ b/include/CLI/impl/Config_inl.hpp @@ -322,6 +322,21 @@ inline std::vector 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)) { diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index 519f05c3a..1941a165c 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -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(); diff --git a/tests/FuzzFailTest.cpp b/tests/FuzzFailTest.cpp index b16760e98..879ef4802 100644 --- a/tests/FuzzFailTest.cpp +++ b/tests/FuzzFailTest.cpp @@ -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) { diff --git a/tests/fuzzFail/round_trip_fail4 b/tests/fuzzFail/round_trip_fail4 new file mode 100644 index 000000000..2e6993487 --- /dev/null +++ b/tests/fuzzFail/round_trip_fail4 @@ -0,0 +1 @@ +'B"(zzzzzz!t0!!!!!--satd!!!!!!!!!--vopt0!!!!!--satd!!!]!!!!!--vopt0-b!!!b!!'B"(zzzzzz!t0!!!!!--satd!!!!!!!!!--vopt0!!!!!--satd!!!]!!!!!--vopt0-b!-bb-satd!! \ No newline at end of file