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 a4ba66b

Browse filesBrowse files
committed
parse empty sequence elements as null
1 parent e104cd2 commit a4ba66b
Copy full SHA for a4ba66b

File tree

2 files changed

+15
-0
lines changed
Filter options

2 files changed

+15
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+8Lines changed: 8 additions & 0 deletions
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

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