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

Skip to content

Commit 77fc10e

Browse files
committed
Fix multidimensional inline yaml collections
1 parent 5e3338c commit 77fc10e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,15 @@ private function lexInlineSequence(string $yaml): string
12401240
}
12411241

12421242
$value = $yaml;
1243+
$collectionLevel = 1;
12431244

12441245
while ($this->moveToNextLine()) {
1245-
for ($i = 1; isset($this->currentLine[$i]) && ']' !== $this->currentLine[$i]; ++$i) {
1246+
for ($i = 1; isset($this->currentLine[$i]) && $collectionLevel >= 1; ++$i) {
1247+
if ('[' === $this->currentLine[$i]) {
1248+
++$collectionLevel;
1249+
} elseif (']' === $this->currentLine[$i]) {
1250+
--$collectionLevel;
1251+
}
12461252
}
12471253

12481254
$trimmedValue = trim($this->currentLine);
@@ -1253,7 +1259,7 @@ private function lexInlineSequence(string $yaml): string
12531259

12541260
$value .= $trimmedValue;
12551261

1256-
if (isset($this->currentLine[$i]) && ']' === $this->currentLine[$i]) {
1262+
if (0 === $collectionLevel) {
12571263
break;
12581264
}
12591265
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,18 @@ public function testParsingMultipleDocuments()
24652465
// (before, there was no \n after row2)
24662466
$this->assertSame(['a' => ['b' => "row\nrow2\n"], 'c' => 'd'], $this->parser->parse($longDocument));
24672467
}
2468+
2469+
public function testParsingMultidimensionalCollectionOverMultipleLines()
2470+
{
2471+
$yaml = <<<YAML
2472+
[
2473+
["entry1", {}],
2474+
["entry2"]
2475+
]
2476+
YAML;
2477+
2478+
$this->assertSame([['entry1', []], ['entry2']], $this->parser->parse($yaml));
2479+
}
24682480
}
24692481

24702482
class B

0 commit comments

Comments
 (0)