Ticket #32 (new defect)
Opened 3 months ago
Parser accepts duplicate keys for mappings
| Reported by: | Derek Poon | Owned by: | somebody |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | component1 | Version: | |
| Keywords: | Cc: |
Description
According to the YAML spec (versions 1.1 and 1.2), mappings may not contain duplicate keys. The following document is invalid:
{ key1: value1, key1: value2 }
From YAML spec section 3.2.1.1: 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.
From YAML spec section 3.3.3: To be valid, a node must have a tag which is recognized by the YAML processor and its content must satisfy the constraints imposed by this tag.
Taken together, the presence of mapping containing duplicate keys should cause the document to fail to load. However, Syck (at least when using the Ruby bindings) constructs a Hash in which the last of such duplicate keys prevails.
In rubyext.c, yaml_org_handler() blindly calls rb_hash_aset(). It should raise an exception if the key is already in the hash.