From b5316ebebb42bfe7b755bb208b84903f55b16a32 Mon Sep 17 00:00:00 2001 From: Andre Eckardt Date: Wed, 2 Sep 2020 22:39:27 +0200 Subject: [PATCH] [Yaml Parser] fixed Parser to skip comments when inlining sequences --- src/Symfony/Component/Yaml/Parser.php | 8 ++++++- .../Component/Yaml/Tests/ParserTest.php | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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'])], + ], + <<