From 9c5f8c6b96faa48b9a2724bd3136e9c14f909aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Thu, 11 Jul 2013 11:21:24 +0200 Subject: [PATCH] [Yaml] removed wrong comment removal inside a string block --- src/Symfony/Component/Yaml/Parser.php | 6 +- .../Component/Yaml/Tests/ParserTest.php | 57 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 4a82b784bc..017a32a227 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -304,14 +304,16 @@ class Parser $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine); - while ($this->moveToNextLine()) { + // We are in string block (ie. after a line ending with "|") + $removeComments = !preg_match('~(.*)\|[\s]*$~', $this->currentLine); + while ($this->moveToNextLine()) { if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine)) { $this->moveToPreviousLine(); break; } - if ($this->isCurrentLineEmpty()) { + if ($removeComments && $this->isCurrentLineEmpty() || $this->isCurrentLineBlank()) { if ($this->isCurrentLineBlank()) { $data[] = substr($this->currentLine, $newIndent); } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index a8d28b9131..a74bd3ee87 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -522,6 +522,63 @@ EOF; $this->assertEquals(array('hash' => null), Yaml::parse($input)); } + + public function testStringBlockWithComments() + { + $this->assertEquals(array('content' => << +

title

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

title

+ + + footer # comment3 +EOF + )); + } + + public function testNestedStringBlockWithComments() + { + $this->assertEquals(array(array('content' => << +

title

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

title

+ + + footer # comment3 +EOF + )); + } } class B