Skip to content

Duplicate keys in Yaml fail silently #19526

Closed
@alexpott

Description

@alexpott

When the yaml parser reads

foo: bar
foo: bar2

It will return an array with the first key. This is unfortunate for a couple of reasons.

  1. It is not to spec. The Yaml spec is clear that duplicate keys should be treated as an error - see http://yaml.org/spec/1.2/spec.html#id2759572
  2. The current behaviour of choosing the first key is pretty unique. See:
Psy Shell v0.7.0 (PHP 7.0.7 — cli) by Justin Hileman
>>> $a = ['a' => '1', 'a' => '2']
=> [
     "a" => "2",
   ]

Also it is the opposite behaviour to the PECL yaml parser (which behaves like PHP) so allowing users to swap between implementations can have interesting affects.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions