From f72c6a5ad40ea5feac5a6d89946c165e95d8f538 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 11 Jan 2021 14:44:09 +0100 Subject: [PATCH] a colon followed by spaces exclusively separates mapping keys and values --- src/Symfony/Component/Yaml/Parser.php | 2 +- src/Symfony/Component/Yaml/Tests/InlineTest.php | 17 +++++++++++++++++ src/Symfony/Component/Yaml/Tests/ParserTest.php | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 8ca26e0e8f..6d0d523265 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -200,7 +200,7 @@ class Parser array_pop($this->refsBeingParsed); } } elseif ( - self::preg_match('#^(?P(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(\s++(?P.+))?$#u', rtrim($this->currentLine), $values) + self::preg_match('#^(?P(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:( ++(?P.+))?$#u', rtrim($this->currentLine), $values) && (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"])) ) { if ($context && 'sequence' == $context) { diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 338ea504a8..66eae463db 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -877,4 +877,21 @@ class InlineTest extends TestCase [['!'], '! ["!"]'], ]; } + + /** + * @dataProvider ideographicSpaceProvider + */ + public function testParseIdeographicSpace(string $yaml, string $expected) + { + $this->assertSame($expected, Inline::parse($yaml)); + } + + public function ideographicSpaceProvider(): array + { + return [ + ["\u{3000}", ' '], + ["'\u{3000}'", ' '], + ["'a b'", 'a b'], + ]; + } } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 1db540369d..1fa448dad5 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -2733,6 +2733,22 @@ YAML; // (before, there was no \n after row2) $this->assertSame(['a' => ['b' => "row\nrow2\n"], 'c' => 'd'], $this->parser->parse($longDocument)); } + + public function testParseIdeographicSpaces() + { + $expected = <<assertSame([ + 'unquoted' => ' ', + 'quoted' => ' ', + 'within_string' => 'a b', + 'regular_space' => 'a b', + ], $this->parser->parse($expected)); + } } class B