Skip to content

Commit 7b35c2d

Browse files
committed
bug symfony#25438 [Yaml] empty lines don't count for indent detection (xabbuh)
This PR was merged into the 3.3 branch. Discussion ---------- [Yaml] empty lines don't count for indent detection | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#25405 | License | MIT | Doc PR | Commits ------- eb073fa empty lines don't count for indent detection
2 parents 50644d0 + eb073fa commit 7b35c2d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,8 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
543543
do {
544544
$EOF = false;
545545

546-
// comment-like lines do not influence the indentation depth
547-
if ($this->isCurrentLineComment()) {
546+
// empty and comment-like lines do not influence the indentation depth
547+
if ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
548548
$EOF = !$this->moveToNextLine();
549549

550550
if (!$EOF) {
@@ -571,7 +571,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
571571
$data = array();
572572
if ($this->getCurrentLineIndentation() >= $newIndent) {
573573
$data[] = substr($this->currentLine, $newIndent);
574-
} elseif ($this->isCurrentLineComment()) {
574+
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
575575
$data[] = $this->currentLine;
576576
} else {
577577
$this->moveToPreviousLine();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,18 @@ public function indentedMappingData()
20732073
);
20742074
$tests['mapping in sequence starting on a new line'] = array($yaml, $expected);
20752075

2076+
$yaml = <<<YAML
2077+
foo:
2078+
2079+
bar: baz
2080+
YAML;
2081+
$expected = array(
2082+
'foo' => array(
2083+
'bar' => 'baz',
2084+
),
2085+
);
2086+
$tests['blank line at the beginning of an indented mapping value'] = array($yaml, $expected);
2087+
20762088
return $tests;
20772089
}
20782090
}

0 commit comments

Comments
 (0)