mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Enforce unique elements in YAML sets.
If a YAML sequence containing non-uniue elements is decoded into a set or unordered_set, it should fail.
This commit is contained in:
@@ -47,7 +47,8 @@ namespace YAML {
|
||||
|
||||
rhs.clear();
|
||||
for (const auto &element : node) {
|
||||
rhs.insert(element.template as<T>());
|
||||
if (!rhs.insert(element.template as<T>()).second)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -80,7 +81,8 @@ namespace YAML {
|
||||
|
||||
rhs.clear();
|
||||
for (const auto &element : node) {
|
||||
rhs.insert(element.template as<T>());
|
||||
if (!rhs.insert(element.template as<T>()).second)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ TEST(set, YamlDecode) {
|
||||
EXPECT_EQ(stringSet.begin(), stringSet.find("a"));
|
||||
EXPECT_EQ(++stringSet.begin(), stringSet.find("b"));
|
||||
EXPECT_EQ(--stringSet.end(), stringSet.find("c"));
|
||||
|
||||
node = YAML::Load("[a, b, c, c]");
|
||||
EXPECT_ANY_THROW(node.as<std::set<std::string>>());
|
||||
}
|
||||
|
||||
TEST(set, YamlEmitter) {
|
||||
@@ -82,6 +85,9 @@ TEST(unordered_set, YAMLDecode) {
|
||||
EXPECT_EQ(1, stringSet.count("a"));
|
||||
EXPECT_EQ(1, stringSet.count("b"));
|
||||
EXPECT_EQ(1, stringSet.count("c"));
|
||||
|
||||
node = YAML::Load("[a, b, c, c]");
|
||||
EXPECT_ANY_THROW(node.as<std::unordered_set<std::string>>());
|
||||
}
|
||||
|
||||
bool sequenceOf(const char val1,
|
||||
|
||||
Reference in New Issue
Block a user