Skip to content

Commit 37b922f

Browse files
xabbuhsymfonyaml
authored and
symfonyaml
committed
parse empty sequence elements as null
1 parent c3ef0fb commit 37b922f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/Yaml/Inline.php

+8
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,18 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
355355
++$i;
356356

357357
// [foo, bar, ...]
358+
$lastToken = null;
358359
while ($i < $len) {
359360
if (']' === $sequence[$i]) {
360361
return $output;
361362
}
362363
if (',' === $sequence[$i] || ' ' === $sequence[$i]) {
364+
if (',' === $sequence[$i] && (null === $lastToken || 'separator' === $lastToken)) {
365+
$output[] = null;
366+
} elseif (',' === $sequence[$i]) {
367+
$lastToken = 'separator';
368+
}
369+
363370
++$i;
364371

365372
continue;
@@ -403,6 +410,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
403410

404411
$output[] = $value;
405412

413+
$lastToken = 'value';
406414
++$i;
407415
}
408416

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

+7
Original file line numberDiff line numberDiff line change
@@ -1004,4 +1004,11 @@ public function testParseQuotedReferenceLikeStringsInSequence()
10041004

10051005
$this->assertSame(['&foo', '&bar', '&baz'], Inline::parse($yaml));
10061006
}
1007+
1008+
public function testParseSequenceWithEmptyElement()
1009+
{
1010+
$this->assertSame(['foo', null, 'bar'], Inline::parse('[foo, , bar]'));
1011+
$this->assertSame([null, 'foo', 'bar'], Inline::parse('[, foo, bar]'));
1012+
$this->assertSame(['foo', 'bar'], Inline::parse('[foo, bar, ]'));
1013+
}
10071014
}

0 commit comments

Comments
 (0)