Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f172cce

Browse filesBrowse files
committed
parse omitted inlined mapping values as null
1 parent 61a67ec commit f172cce
Copy full SHA for f172cce

File tree

2 files changed

+31
-1
lines changed
Filter options

2 files changed

+31
-1
lines changed

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

@@ -501,6 +501,20 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
501501
case ':':
502502
case ' ':
503503
break;
504+
case ',':
505+
case '}':
506+
// Spec: Keys MUST be unique; first one wins.
507+
// Parser cannot abort this mapping earlier, since lines
508+
// are processed sequentially.
509+
if (!isset($output[$key])) {
510+
$output[$key] = null;
511+
} else {
512+
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
513+
}
514+
515+
$done = true;
516+
--$i;
517+
break;
504518
default:
505519
$value = self::parseScalar($mapping, $flags, array(',', '}'), array('"', "'"), $i, true, $references);
506520
// Spec: Keys MUST be unique; first one wins.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+16Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.