Skip to content

Validate mapping key uniqueness#1221

Merged
SGSSGene merged 1 commit intojbeder:masterfrom
brondani:validate-mapping-key-uniqueness
Mar 12, 2026
Merged

Validate mapping key uniqueness#1221
SGSSGene merged 1 commit intojbeder:masterfrom
brondani:validate-mapping-key-uniqueness

Conversation

@brondani
Copy link
Copy Markdown
Contributor

@brondani brondani commented Sep 1, 2023

According to YAML spec 1.2.2:

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.

The changes proposed here check the uniqueness of scalar mapping keys, throwing a NonUniqueMapKey exception when by inserting a new key/value pair an identical scalar key is already present in a mapping. Non identical but equivalent scalar content, for example “0o13” (octal) or “0xB” (hexadecimal), are not considered.

Address #60.

@apirogov
Copy link
Copy Markdown

Would like to see this merged. It's a common source of problems to have duplicate keys in a map and have the content being overridden silently. We have huge config files with YAML and it's easy to miss an existing entry and duplicate it, causing issues due to the silent overriding.

@matemat13
Copy link
Copy Markdown

seconded...

@SGSSGene
Copy link
Copy Markdown
Collaborator

@brondani could you update this PR? I would like to merge it.

@brondani brondani force-pushed the validate-mapping-key-uniqueness branch from 45c6b77 to 486d7e7 Compare March 12, 2026 13:58
@brondani
Copy link
Copy Markdown
Contributor Author

@SGSSGene

could you update this PR? I would like to merge it.

Done.

@SGSSGene SGSSGene merged commit 6f3b99c into jbeder:master Mar 12, 2026
43 checks passed
@SGSSGene
Copy link
Copy Markdown
Collaborator

Thank you!

@PhilipDeegan
Copy link
Copy Markdown
Contributor

include/yaml-cpp/exceptions.h:309:49: error: unused parameter 'key' [-Werror,-Wunused-parameter]
  NonUniqueMapKey(const Mark& mark_, const Key& key)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants