mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-29 12:37:30 -03:00
util: fix argsman dupe key error
fixes #22638
If we find a duplicate key and error, clear `values` before returning so that
WriteSettings will write an empty file, therefore clearing it.
This aligns with GUI behaviour added in 1ee6d0b
.
This commit is contained in:
parent
f7bdcfc83f
commit
8fcbdadfad
2 changed files with 4 additions and 1 deletions
|
@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(ReadWrite)
|
||||||
BOOST_CHECK(values.empty());
|
BOOST_CHECK(values.empty());
|
||||||
BOOST_CHECK(errors.empty());
|
BOOST_CHECK(errors.empty());
|
||||||
|
|
||||||
// Check duplicate keys not allowed
|
// Check duplicate keys not allowed and that values returns empty if a duplicate is found.
|
||||||
WriteText(path, R"({
|
WriteText(path, R"({
|
||||||
"dupe": "string",
|
"dupe": "string",
|
||||||
"dupe": "dupe"
|
"dupe": "dupe"
|
||||||
|
@ -88,6 +88,7 @@ BOOST_AUTO_TEST_CASE(ReadWrite)
|
||||||
BOOST_CHECK(!util::ReadSettings(path, values, errors));
|
BOOST_CHECK(!util::ReadSettings(path, values, errors));
|
||||||
std::vector<std::string> dup_keys = {strprintf("Found duplicate key dupe in settings file %s", fs::PathToString(path))};
|
std::vector<std::string> dup_keys = {strprintf("Found duplicate key dupe in settings file %s", fs::PathToString(path))};
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), dup_keys.begin(), dup_keys.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), dup_keys.begin(), dup_keys.end());
|
||||||
|
BOOST_CHECK(values.empty());
|
||||||
|
|
||||||
// Check non-kv json files not allowed
|
// Check non-kv json files not allowed
|
||||||
WriteText(path, R"("non-kv")");
|
WriteText(path, R"("non-kv")");
|
||||||
|
|
|
@ -99,6 +99,8 @@ bool ReadSettings(const fs::path& path, std::map<std::string, SettingsValue>& va
|
||||||
auto inserted = values.emplace(in_keys[i], in_values[i]);
|
auto inserted = values.emplace(in_keys[i], in_values[i]);
|
||||||
if (!inserted.second) {
|
if (!inserted.second) {
|
||||||
errors.emplace_back(strprintf("Found duplicate key %s in settings file %s", in_keys[i], fs::PathToString(path)));
|
errors.emplace_back(strprintf("Found duplicate key %s in settings file %s", in_keys[i], fs::PathToString(path)));
|
||||||
|
values.clear();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.empty();
|
return errors.empty();
|
||||||
|
|
Loading…
Add table
Reference in a new issue