diff --git a/include/CLI/impl/App_inl.hpp b/include/CLI/impl/App_inl.hpp index 2692e74bc..92a279a3a 100644 --- a/include/CLI/impl/App_inl.hpp +++ b/include/CLI/impl/App_inl.hpp @@ -723,7 +723,8 @@ CLI11_NODISCARD CLI11_INLINE std::string App::help(std::string prev, AppFormatMo CLI11_NODISCARD CLI11_INLINE std::string App::version() const { std::string val; if(version_ptr_ != nullptr) { - auto rv = version_ptr_->results(); + // copy the results for reuse later + results_t rv = version_ptr_->results(); version_ptr_->clear(); version_ptr_->add_result("true"); try { @@ -1479,7 +1480,46 @@ CLI11_INLINE bool App::_parse_single_config(const ConfigItem &item, std::size_t if(op->get_items_expected_max() > 1) { throw ArgumentMismatch::AtMost(item.fullname(), op->get_items_expected_max(), item.inputs.size()); } - throw ConversionError::TooManyInputsFlag(item.fullname()); + if (op->get_disable_flag_override()) + { + for (const auto& res : item.inputs) + { + bool valid_value{false}; + if (op->default_flag_values_.empty()) + { + if (res == "true" || res == "false" || res == "1" || res == "0") { + valid_value=true; + } + } + else + { + for (const auto& valid_res : op->default_flag_values_) + { + if (valid_res.second == res) + { + valid_value=true; + break; + } + } + + } + + if (valid_value) + { + op->add_result(res); + } + else + { + throw InvalidError("invalid flag argument given"); + } + } + return true; + } + else + { + throw ConversionError::TooManyInputsFlag(item.fullname()); + } + } } op->add_result(item.inputs); diff --git a/include/CLI/impl/Config_inl.hpp b/include/CLI/impl/Config_inl.hpp index b6471745c..1ec57826f 100644 --- a/include/CLI/impl/Config_inl.hpp +++ b/include/CLI/impl/Config_inl.hpp @@ -437,7 +437,8 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description, } } if(!valid) { - throw; + value = detail::ini_join( + opt->results(), arraySeparator, arrayStart, arrayEnd, stringQuote, characterQuote); } } } diff --git a/tests/FuzzFailTest.cpp b/tests/FuzzFailTest.cpp index 49d5dcac0..3c80e5ccb 100644 --- a/tests/FuzzFailTest.cpp +++ b/tests/FuzzFailTest.cpp @@ -63,7 +63,7 @@ TEST_CASE("app_file_gen_fail") { CLI::FuzzApp fuzzdata; auto app = fuzzdata.generateApp(); - int index = GENERATE(range(1, 4)); + int index = GENERATE(range(1, 5)); std::string optionString, flagString; auto parseData = loadFailureFile("fuzz_app_file_fail", index); if(parseData.size() > 25) { diff --git a/tests/fuzzFail/fuzz_app_file_fail4 b/tests/fuzzFail/fuzz_app_file_fail4 new file mode 100644 index 000000000..5c801a73f --- /dev/null +++ b/tests/fuzzFail/fuzz_app_file_fail4 @@ -0,0 +1 @@ +-ccaaaa \ No newline at end of file