From c02dca3483da4ce5f57922d709477aefb165d8f6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Feb 2017 07:51:07 +0100 Subject: [PATCH] [Yaml] deprecate parsing mappings without keys --- UPGRADE-3.3.md | 2 ++ UPGRADE-4.0.md | 2 ++ src/Symfony/Component/Yaml/CHANGELOG.md | 5 +++++ src/Symfony/Component/Yaml/Inline.php | 4 ++++ src/Symfony/Component/Yaml/Tests/InlineTest.php | 4 ++++ 5 files changed, 17 insertions(+) diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 33746f26ce97..5dcdbf5d82a9 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -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 diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 8532532f52f7..5dec4ee41453 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -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`). diff --git a/src/Symfony/Component/Yaml/CHANGELOG.md b/src/Symfony/Component/Yaml/CHANGELOG.md index 45c331f98696..73d70f7184f8 100644 --- a/src/Symfony/Component/Yaml/CHANGELOG.md +++ b/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 ----- diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 1510f4faf977..c71c2ddde128 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -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); } diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 198f3cbc8273..32aa448fb2f1 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -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}'));