Skip to content

Commit c473504

Browse files
committed
parse omitted inlined mapping values as null
1 parent 36dacbc commit c473504

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/Symfony/Component/Yaml/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
3.3.0
55
-----
66

7+
* Omitted mapping values will be parsed as `null`.
8+
79
* Omitting the key of a mapping is deprecated and will throw a `ParseException` in Symfony 4.0.
810

911
* Added support for dumping empty PHP arrays as YAML sequences:

src/Symfony/Component/Yaml/Inline.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i
318318
if (preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
319319
$output = substr($output, 0, $match[0][1]);
320320
}
321-
} elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
321+
} elseif (preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
322322
$output = $match[1];
323323
$i += strlen($output);
324324
} else {

src/Symfony/Component/Yaml/Tests/InlineTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,20 @@ public function testOmittedMappingKeyIsParsedAsColon()
702702
{
703703
$this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}'));
704704
}
705+
706+
/**
707+
* @dataProvider getTestsForNullValues
708+
*/
709+
public function testParseMissingMappingValueAsNull($yaml, $expected)
710+
{
711+
$this->assertSame($expected, Inline::parse($yaml));
712+
}
713+
714+
public function getTestsForNullValues()
715+
{
716+
return array(
717+
'null before closing curly brace' => array('{foo:}', array('foo' => null)),
718+
'null before comma' => array('{foo:, bar: baz}', array('foo' => null, 'bar' => 'baz')),
719+
);
720+
}
705721
}

0 commit comments

Comments
 (0)