From e2ebecc0cb26d40639a6b236ff2c9b485c860093 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Feb 2017 11:55:39 +0100 Subject: [PATCH] consistently parse omitted keys as the colon --- src/Symfony/Component/Yaml/Inline.php | 4 ++-- src/Symfony/Component/Yaml/Tests/InlineTest.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 8f846b2ba43a..14137f14b7d2 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -459,11 +459,11 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar // key $key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false); - if (false === $i = strpos($mapping, ':', $i)) { + if (':' !== $key && false === $i = strpos($mapping, ':', $i)) { break; } - if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true)) { + 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 137ef5706836..198f3cbc8273 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -686,4 +686,9 @@ public function testVeryLongQuotedStrings() $this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']); } + + public function testOmittedMappingKeyIsParsedAsColon() + { + $this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}')); + } }