From dc8898aec40a936828947482c880e32944254dc6 Mon Sep 17 00:00:00 2001 From: Link1515 Date: Sat, 28 Dec 2024 09:17:00 +0800 Subject: [PATCH] [Yaml] Fix parsing of unquoted strings in Parser::lexUnquotedString() to ignore spaces --- src/Symfony/Component/Yaml/Parser.php | 2 +- .../Component/Yaml/Tests/ParserTest.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 2a15bcae3d157..6d7064e07abb8 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -1158,7 +1158,7 @@ private function lexInlineQuotedString(int &$cursor = 0): string private function lexUnquotedString(int &$cursor): string { $offset = $cursor; - $cursor += strcspn($this->currentLine, '[]{},: ', $cursor); + $cursor += strcspn($this->currentLine, '[]{},:', $cursor); if ($cursor === $offset) { throw new ParseException('Malformed unquoted YAML string.'); diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 3c4c071135855..23119f92176b8 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1710,6 +1710,33 @@ public function testBackslashInQuotedMultiLineString() $this->assertSame($expected, $this->parser->parse($yaml)); } + /** + * @dataProvider wrappedUnquotedStringsProvider + */ + public function testWrappedUnquotedStringWithMultipleSpacesInValue(string $yaml, array $expected) + { + $this->assertSame($expected, $this->parser->parse($yaml)); + } + + public static function wrappedUnquotedStringsProvider() { + return [ + 'mapping' => [ + '{ foo: bar bar, fiz: cat cat }', + [ + 'foo' => 'bar bar', + 'fiz' => 'cat cat', + ] + ], + 'sequence' => [ + '[ bar bar, cat cat ]', + [ + 'bar bar', + 'cat cat', + ] + ], + ]; + } + public function testParseMultiLineUnquotedString() { $yaml = <<