parse omitted inlined mapping values as null

This commit is contained in:
Christian Flothmann 2017-01-01 11:29:29 +01:00
parent 36dacbc4a1
commit c473504a95
3 changed files with 19 additions and 1 deletions

View File

@ -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:

View File

@ -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 {

View File

@ -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')),
);
}
}