diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 0c4a76e2b189e..56322c387d386 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -741,11 +741,11 @@ private function parseValue(string $value, int $flags, string $context) try { if ('' !== $value && '{' === $value[0]) { - $cursor = \strlen($this->currentLine) - \strlen($value); + $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value)); return Inline::parse($this->lexInlineMapping($cursor), $flags, $this->refs); } elseif ('' !== $value && '[' === $value[0]) { - $cursor = \strlen($this->currentLine) - \strlen($value); + $cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value)); return Inline::parse($this->lexInlineSequence($cursor), $flags, $this->refs); } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index a9715151f1b03..cea3d3f330a71 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -2671,6 +2671,29 @@ public function testParseValueWithNegativeModifiers() ); } + public function testMultipleWhitespaceAtEndOfLine() + { + $yaml = "\nfoo:\n arguments: [ '@bar' ] \n"; + $this->assertSame( + [ + 'foo' => [ + 'arguments' => ['@bar'], + ], + ], + $this->parser->parse($yaml) + ); + + $yaml = "\nfoo:\n bar: {} \n"; + $this->assertSame( + [ + 'foo' => [ + 'bar' => [], + ], + ], + $this->parser->parse($yaml) + ); + } + /** * This is a regression test for a bug where a YAML block with a nested multiline string using | was parsed without * a trailing \n when a shorter YAML document was parsed before.