From c473504a95ecd1412bdec26bccf65b3245209a5d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 1 Jan 2017 11:29:29 +0100 Subject: [PATCH] parse omitted inlined mapping values as null --- src/Symfony/Component/Yaml/CHANGELOG.md | 2 ++ src/Symfony/Component/Yaml/Inline.php | 2 +- src/Symfony/Component/Yaml/Tests/InlineTest.php | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/CHANGELOG.md b/src/Symfony/Component/Yaml/CHANGELOG.md index 966cb735da..6951c94368 100644 --- a/src/Symfony/Component/Yaml/CHANGELOG.md +++ b/src/Symfony/Component/Yaml/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 3.3.0 ----- + * Omitted mapping values will be parsed as `null`. + * Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0. * Added support for dumping empty PHP arrays as YAML sequences: diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index b555f0ee13..5b2fe7af96 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -318,7 +318,7 @@ class Inline if (preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) { $output = substr($output, 0, $match[0][1]); } - } elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { + } elseif (preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) { $output = $match[1]; $i += strlen($output); } else { diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 7aec07972b..1d1c013f67 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -702,4 +702,20 @@ class InlineTest extends TestCase { $this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}')); } + + /** + * @dataProvider getTestsForNullValues + */ + public function testParseMissingMappingValueAsNull($yaml, $expected) + { + $this->assertSame($expected, Inline::parse($yaml)); + } + + public function getTestsForNullValues() + { + return array( + 'null before closing curly brace' => array('{foo:}', array('foo' => null)), + 'null before comma' => array('{foo:, bar: baz}', array('foo' => null, 'bar' => 'baz')), + ); + } }