From 0e24fc582027ee4d786235c9dbc2c5ae18d1b34b Mon Sep 17 00:00:00 2001 From: "maxime.steinhausser" Date: Mon, 21 Sep 2015 15:29:45 +0200 Subject: [PATCH] [Yaml] Fix improper comments removal inside strings --- src/Symfony/Component/Yaml/Parser.php | 12 ------ .../Component/Yaml/Tests/ParserTest.php | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index fd7ded094f699..5e52c3ef8b24b 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -337,17 +337,9 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false) $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine); - // Comments must not be removed inside a string block (ie. after a line ending with "|") - $removeCommentsPattern = '~'.self::FOLDED_SCALAR_PATTERN.'$~'; - $removeComments = !preg_match($removeCommentsPattern, $this->currentLine); - while ($this->moveToNextLine()) { $indent = $this->getCurrentLineIndentation(); - if ($indent === $newIndent) { - $removeComments = !preg_match($removeCommentsPattern, $this->currentLine); - } - if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) { $this->moveToPreviousLine(); break; @@ -358,10 +350,6 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false) continue; } - if ($removeComments && $this->isCurrentLineComment()) { - continue; - } - if ($indent >= $newIndent) { $data[] = substr($this->currentLine, $newIndent); } elseif (0 == $indent) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 3054c807fdd12..21fdd1bf70f4d 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -617,6 +617,43 @@ public function testFoldedStringBlockWithComments() )); } + public function testSecondLevelFoldedStringBlockWithComments() + { + $this->assertEquals(array( + 'pages' => array( + array( + 'title' => 'some title', + 'content' => << +

title

+ + +footer # comment3 +EOT + ), + ), + ), Yaml::parse(<< +

title

+ + + footer # comment3 +EOF + )); + } + public function testNestedFoldedStringBlockWithComments() { $this->assertEquals(array(array(