Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8103249

Browse files
committed
parse omitted inlined mapping values as null
1 parent c5bdfc5 commit 8103249

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,20 @@ public function testVeryLongQuotedStrings()
686686

687687
$this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']);
688688
}
689+
690+
/**
691+
* @dataProvider getTestsForNullValues
692+
*/
693+
public function testParseMissingMappingValueAsNull($yaml, $expected)
694+
{
695+
$this->assertSame($expected, Inline::parse($yaml));
696+
}
697+
698+
public function getTestsForNullValues()
699+
{
700+
return array(
701+
'null before closing curly brace' => array('{foo:}', array('foo' => null)),
702+
'null before comma' => array('{foo:, bar: baz}', array('foo' => null, 'bar' => 'baz')),
703+
);
704+
}
689705
}

0 commit comments

Comments
 (0)