diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index e51391f35deaa..edef30b3745e9 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -529,8 +529,8 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f do { $EOF = false; - // empty and comment-like lines do not influence the indentation depth - if ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) { + // empty, quotation mark only, and comment-like lines do not influence the indentation depth + if ($this->isCurrentLineEmpty() || $this->isCurrentLineComment() || $this->isCurrentLineQuotationOnly()) { $EOF = !$this->moveToNextLine(); if (!$EOF) { @@ -557,7 +557,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f $data = []; if ($this->getCurrentLineIndentation() >= $newIndent) { $data[] = substr($this->currentLine, $newIndent); - } elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) { + } elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment() || $this->isCurrentLineQuotationOnly()) { $data[] = $this->currentLine; } else { $this->moveToPreviousLine(); @@ -590,7 +590,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f if ($indent >= $newIndent) { $data[] = substr($this->currentLine, $newIndent); - } elseif ($this->isCurrentLineComment()) { + } elseif ($this->isCurrentLineComment() || $this->isCurrentLineQuotationOnly()) { $data[] = $this->currentLine; } elseif (0 == $indent) { $this->moveToPreviousLine(); @@ -916,6 +916,18 @@ private function isCurrentLineComment(): bool return '' !== $ltrimmedLine && '#' === $ltrimmedLine[0]; } + /** + * Returns true if the current line contains quotation mark only. + * + * @return bool Returns true if the current line contains quotation mark only, false otherwise + */ + private function isCurrentLineQuotationOnly(): bool + { + $trimmedLine = trim($this->currentLine, ' '); + + return 1 == \strlen($trimmedLine) && '' !== $trimmedLine && ("'" === $trimmedLine[0] || '"' === $trimmedLine[0]); + } + private function isCurrentLineLastLineInDocument(): bool { return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1); diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 366902a8647e4..3c0596b16531c 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -2150,6 +2150,38 @@ public function testParseValueWithNegativeModifiers() $this->parser->parse($yaml) ); } + + public function testParseValueWithUnindentedClosingQuotation() + { + $expected = ['foo' => ['bar' => 'baz ']]; + + // unindented closing single quote + $yaml = <<assertSame($expected, $this->parser->parse($yaml)); + + // unindented closing double quote + $yaml = <<assertSame($expected, $this->parser->parse($yaml)); + + // correctly-indented closing double quote + $yaml = <<assertSame($expected, $this->parser->parse($yaml)); + } } class B