diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index e859766f97..6d8e79b271 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -230,8 +230,12 @@ class Parser $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags) ); } else { - if (isset($values['leadspaces']) - && self::preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P.+?))?\s*$#u', $this->trimTag($values['value']), $matches) + if ( + isset($values['leadspaces']) + && ( + '!' === $values['value'][0] + || self::preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P.+?))?\s*$#u', $this->trimTag($values['value']), $matches) + ) ) { // this is a compact notation element, add to next block and parse $block = $values['value']; diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index b6cdb6a9aa..1627389bf8 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -2025,6 +2025,34 @@ YAML; $this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT | Yaml::PARSE_KEYS_AS_STRINGS)); } + public function testPhpConstantTagMappingAsScalarKey() + { + $yaml = <<assertSame([ + 'map1' => [['foo' => 'value_0', 'bar' => 'value_1']], + 'map2' => [['foo' => 'value_0', 'bar' => 'value_1']], + ], $this->parser->parse($yaml, Yaml::PARSE_CONSTANT)); + } + + public function testTagMappingAsScalarKey() + { + $yaml = <<assertSame([ + 'map1' => [['0' => 'value_0', '1' => 'value_1']], + ], $this->parser->parse($yaml)); + } + public function testMergeKeysWhenMappingsAreParsedAsObjects() { $yaml = <<assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));