Skip to content

Commit

Permalink
[Yaml] deprecate parsing mappings without keys
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Feb 17, 2017
1 parent 0a3cd97 commit c02dca3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions UPGRADE-3.3.md
Expand Up @@ -119,6 +119,8 @@ Workflow
Yaml
----

* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.

* The constructor arguments `$offset`, `$totalNumberOfLines` and
`$skippedLineNumbers` of the `Parser` class are deprecated and will be
removed in 4.0
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Expand Up @@ -340,6 +340,8 @@ Validator
Yaml
----

* Omitting the key of a mapping is not supported anymore and throws a `ParseException`.

* Mappings with a colon (`:`) that is not followed by a whitespace are not
supported anymore and lead to a `ParseException`(e.g. `foo:bar` must be
`foo: bar`).
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Yaml/CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========

3.3.0
-----

* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.

3.2.0
-----

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -481,6 +481,10 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
break;
}

if (':' === $key) {
@trigger_error('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
}

if (':' !== $key && (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
@trigger_error('Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Expand Up @@ -687,6 +687,10 @@ public function testVeryLongQuotedStrings()
$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
}

/**
* @group legacy
* @expectedDeprecation Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.
*/
public function testOmittedMappingKeyIsParsedAsColon()
{
$this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}'));
Expand Down

0 comments on commit c02dca3

Please sign in to comment.