Skip to content

[Yaml] Fixed YAML Parser does not ignore duplicate keys, violating YAML spec. #10902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2014

Conversation

sun
Copy link
Contributor

@sun sun commented May 15, 2014

Q A
Bug fix? yes
New feature? no
BC breaks? mayhaps
Deprecations? no
Tests pass? yes
Needs merge to 2.4
Fixed tickets
License MIT
Doc PR

The current YAML 1.2 specification clearly states:

JSON's RFC4627 requires that mappings keys merely “SHOULD” be unique, while YAML insists they “MUST” be.

The outdated YAML 1.1 spec contained a crystal clear note on how the error of duplicate keys is to be handled by parsers, which is (sadly) no longer contained in the latest 1.2 spec (only leaving the requirement):

It is an error for two equal keys to appear in the same mapping node. In such a case the YAML processor may continue, ignoring the second key: value pair and issuing an appropriate warning. This strategy preserves a consistent information model for one-pass and random access applications.

@sun
Copy link
Contributor Author

sun commented May 15, 2014

To my knowledge, this turns Symfony's YAML parser into the first of all PHP implementations that does not violate the spec on the aspect of duplicate keys.

The PECL YAML extension also fails on that requirement.

FWIW, Python's PyYAML is struggling with this bug, too.

@sun
Copy link
Contributor Author

sun commented May 15, 2014

The reported test failures are not related to this PR:

Running src/Symfony/Component/Yaml tests
OK (177 tests, 463 assertions)

@jakzal jakzal added the Yaml label May 15, 2014
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
if (!isset($output[$key])) {
$output[$key] = $value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use 4 spaces for the indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that; fixed now.

The current [YAML 1.2] specification clearly states:

> JSON's RFC4627 requires that mappings keys merely “SHOULD” be unique, while YAML insists they “MUST” be.

The outdated [YAML 1.1] spec contained a crystal clear note on how the error of duplicate keys is to be handled by parsers, which is (sadly) no longer contained in the latest 1.2 spec (only leaving the requirement):

> It is an error for two equal keys to appear in the same mapping node.  In such a case the YAML processor may continue, ignoring the second `key: value` pair and issuing an appropriate warning.  This strategy preserves a consistent information model for one-pass and random access applications.

[YAML 1.2]: http://yaml.org/spec/1.2/spec.html#id2759572
[YAML 1.1]: http://yaml.org/spec/1.1/#id932806
@fabpot
Copy link
Member

fabpot commented May 16, 2014

Thanks for fixing this bug @sun.

@fabpot fabpot merged commit 951acca into symfony:master May 16, 2014
fabpot added a commit that referenced this pull request May 16, 2014
…iolating YAML spec. (sun)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[Yaml] Fixed YAML Parser does not ignore duplicate keys, violating YAML spec.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | **mayhaps**
| Deprecations? | no
| Tests pass?   | yes
| Needs merge to | 2.4
| Fixed tickets | —
| License       | MIT
| Doc PR        | —

The current [YAML 1.2] specification clearly states:

> JSON's RFC4627 requires that mappings keys merely “SHOULD” be unique, while YAML insists they “MUST” be.

The outdated [YAML 1.1] spec contained a crystal clear note on how the error of duplicate keys is to be handled by parsers, which is (sadly) no longer contained in the latest 1.2 spec (only leaving the requirement):

> It is an error for two equal keys to appear in the same mapping node.  In such a case the YAML processor may continue, ignoring the second `key: value` pair and issuing an appropriate warning.  This strategy preserves a consistent information model for one-pass and random access applications.

[YAML 1.2]: http://yaml.org/spec/1.2/spec.html#id2759572
[YAML 1.1]: http://yaml.org/spec/1.1/#id932806

Commits
-------

951acca Fixed YAML Parser does not ignore duplicate keys, violating YAML spec.
@Tobion
Copy link
Contributor

Tobion commented Jun 16, 2014

This is actually a huge BC break. It was a crucial feature to be able to overwrite specific settings later. For example we used YAML aliases and with a following overwrite alot for defining the elasticsearch mapping in Elastica. I don't see how we can solve this now without copying most of the config.

@Tobion
Copy link
Contributor

Tobion commented Jun 17, 2014

OK I found the problem. This PR introduced bug #11142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants