From b562a54e5376583e4a260e64cbcd83c8ecb4d465 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Mon, 30 Nov 2020 11:43:40 +0100 Subject: [PATCH 1/2] Added test for issue 39229 --- .../Component/Yaml/Tests/ParserTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index a9715151f1b03..3f228a45761e2 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. From 66bc898f611efad4a64f7f938c678cc1a0abe4ed Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 30 Nov 2020 13:47:21 +0100 Subject: [PATCH 2/2] fix lexing inline sequences/mappings with trailing whitespaces --- src/Symfony/Component/Yaml/Parser.php | 4 ++-- src/Symfony/Component/Yaml/Tests/ParserTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 3f228a45761e2..cea3d3f330a71 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -2683,7 +2683,7 @@ public function testMultipleWhitespaceAtEndOfLine() $this->parser->parse($yaml) ); - $yaml = "\nfoo:\n bar: {}\n"; + $yaml = "\nfoo:\n bar: {} \n"; $this->assertSame( [ 'foo' => [