diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index b75af76aaf..827847a2b5 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -1244,7 +1244,13 @@ class Parser for ($i = 1; isset($this->currentLine[$i]) && ']' !== $this->currentLine[$i]; ++$i) { } - $value .= trim($this->currentLine); + $trimmedValue = trim($this->currentLine); + + if ('' !== $trimmedValue && '#' === $trimmedValue[0]) { + continue; + } + + $value .= $trimmedValue; if (isset($this->currentLine[$i]) && ']' === $this->currentLine[$i]) { break; diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 8d278d9102..2c19375c25 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1898,6 +1898,30 @@ YAML [new TaggedValue('foo', 'bar')], '[ !foo bar ]', ], + 'with-comments' => [ + [ + [new TaggedValue('foo', ['foo', 'baz'])], + ], + << [ + [ + [new TaggedValue('foo', ['foo', 'baz'])], + ], + <<