The revert reason is fixed in
D143727 (test changes).
According to YAML specification keys must be unique for a mapping node:
"The content of a mapping node is an unordered set of key/value node pairs, with
the restriction that each of the keys is unique".
Differential Revision: https://reviews.llvm.org/
D140474
// Copy string to permanent storage
KeyStr = StringStorage.str().copy(StringAllocator);
}
+ if (mapHNode->Mapping.count(KeyStr))
+ // From YAML spec: "The content of a mapping node is an unordered set of
+ // key/value node pairs, with the restriction that each of the keys is
+ // unique."
+ setError(KeyNode, Twine("duplicated mapping key '") + KeyStr + "'");
auto ValueHNode = createHNodes(Value);
if (EC)
break;
EXPECT_TRUE(!!yin.error());
}
+TEST(YAMLIO, TestMapDuplicatedKeysRead) {
+ auto testDiagnostic = [](const llvm::SMDiagnostic &Error, void *) {
+ EXPECT_EQ(Error.getMessage(), "duplicated mapping key 'foo'");
+ };
+ FooBar doc;
+ Input yin("{foo: 3, bar: 5, foo: 4}", nullptr, testDiagnostic);
+ yin >> doc;
+ EXPECT_TRUE(!!yin.error());
+}
+
//
// Test the reading of a yaml sequence of mappings
//