Skip to content

Commit 47afa60

Browse files
committed
parse omitted inlined mapping values as null
1 parent 61a67ec commit 47afa60

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public static function parseScalar($scalar, $flags = 0, $delimiters = null, $str
309309
if (preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
310310
$output = substr($output, 0, $match[0][1]);
311311
}
312-
} elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
312+
} elseif (preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
313313
$output = $match[1];
314314
$i += strlen($output);
315315
} else {
@@ -463,7 +463,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
463463
break;
464464
}
465465

466-
if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', '[', ']', '{', '}'), true)) {
466+
if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true)) {
467467
@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);
468468
}
469469

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,4 +676,20 @@ public function testNotSupportedMissingValue()
676676
{
677677
Inline::parse('{this, is not, supported}');
678678
}
679+
680+
/**
681+
* @dataProvider getTestsForNullValues
682+
*/
683+
public function testParseMissingMappingValueAsNull($yaml, $expected)
684+
{
685+
$this->assertSame($expected, Inline::parse($yaml));
686+
}
687+
688+
public function getTestsForNullValues()
689+
{
690+
return array(
691+
'null before closing curly brace' => array('{foo:}', array('foo' => null)),
692+
'null before comma' => array('{foo:, bar: baz}', array('foo' => null, 'bar' => 'baz')),
693+
);
694+
}
679695
}

0 commit comments

Comments
 (0)