diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-06-03 12:14:33 +0200 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2021-06-30 10:39:33 +0800 |
commit | da816247f0c00e1644f7ebe2b848cfd6a5c7026e (patch) | |
tree | a907e868a01635b9357045ed003c4f8662f72f41 | |
parent | 513613d8a87337f1d1f639bc9426165c3b6be62e (diff) | |
download | bitcoin-da816247f0c00e1644f7ebe2b848cfd6a5c7026e.tar.xz |
util: Properly handle -noincludeconf on command line
This bug was introduced in commit
fad0867d6ab9430070aa7d60bf7617a6508e0586.
Unit test
Co-Authored-By: Russell Yanofsky <russ@yanofsky.org>
Github-Pull: #22137
Rebased-From: fa910b47656d0e69cccb1f31804f2b11aa45d053
-rw-r--r-- | src/test/util_tests.cpp | 19 | ||||
-rw-r--r-- | src/util/system.cpp | 11 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 010b6adf1f..cc58f64555 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -318,6 +318,25 @@ BOOST_FIXTURE_TEST_CASE(util_CheckValue, CheckValueTest) CheckValue(M::ALLOW_ANY, "-value=abc", Expect{"abc"}.String("abc").Int(0).Bool(false).List({"abc"})); } +struct NoIncludeConfTest { + std::string Parse(const char* arg) + { + TestArgsManager test; + test.SetupArgs({{"-includeconf", ArgsManager::ALLOW_ANY}}); + std::array<const char*, 2> argv{"ignored", arg}; + std::string error; + (void)test.ParseParameters(argv.size(), argv.data(), error); + return error; + } +}; + +BOOST_FIXTURE_TEST_CASE(util_NoIncludeConf, NoIncludeConfTest) +{ + BOOST_CHECK_EQUAL(Parse("-noincludeconf"), ""); + BOOST_CHECK_EQUAL(Parse("-includeconf"), "-includeconf cannot be used from commandline; -includeconf=\"\""); + BOOST_CHECK_EQUAL(Parse("-includeconf=file"), "-includeconf cannot be used from commandline; -includeconf=\"file\""); +} + BOOST_AUTO_TEST_CASE(util_ParseParameters) { TestArgsManager testArgs; diff --git a/src/util/system.cpp b/src/util/system.cpp index a21d58a19d..0d8b669b79 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -336,11 +336,14 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin m_settings.command_line_options[key].push_back(value); } - // we do not allow -includeconf from command line + // we do not allow -includeconf from command line, only -noincludeconf if (auto* includes = util::FindKey(m_settings.command_line_options, "includeconf")) { - const auto& include{*util::SettingsSpan(*includes).begin()}; // pick first value as example - error = "-includeconf cannot be used from commandline; -includeconf=" + include.write(); - return false; + const util::SettingsSpan values{*includes}; + // Range may be empty if -noincludeconf was passed + if (!values.empty()) { + error = "-includeconf cannot be used from commandline; -includeconf=" + values.begin()->write(); + return false; // pick first value as example + } } return true; } |