[Yaml] Fix for #36624; Allow PHP constant as first key in block
This commit is contained in:
parent
995d784a0d
commit
46f635c492
@ -230,8 +230,12 @@ class Parser
|
|||||||
$this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags)
|
$this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (isset($values['leadspaces'])
|
if (
|
||||||
&& self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
|
isset($values['leadspaces'])
|
||||||
|
&& (
|
||||||
|
'!' === $values['value'][0]
|
||||||
|
|| self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
// this is a compact notation element, add to next block and parse
|
// this is a compact notation element, add to next block and parse
|
||||||
$block = $values['value'];
|
$block = $values['value'];
|
||||||
|
@ -2025,6 +2025,34 @@ YAML;
|
|||||||
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT | Yaml::PARSE_KEYS_AS_STRINGS));
|
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT | Yaml::PARSE_KEYS_AS_STRINGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPhpConstantTagMappingAsScalarKey()
|
||||||
|
{
|
||||||
|
$yaml = <<<YAML
|
||||||
|
map1:
|
||||||
|
- foo: 'value_0'
|
||||||
|
!php/const 'Symfony\Component\Yaml\Tests\B::BAR': 'value_1'
|
||||||
|
map2:
|
||||||
|
- !php/const 'Symfony\Component\Yaml\Tests\B::FOO': 'value_0'
|
||||||
|
bar: 'value_1'
|
||||||
|
YAML;
|
||||||
|
$this->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 = <<<YAML
|
||||||
|
map1:
|
||||||
|
- !!str 0: 'value_0'
|
||||||
|
!!str 1: 'value_1'
|
||||||
|
YAML;
|
||||||
|
$this->assertSame([
|
||||||
|
'map1' => [['0' => 'value_0', '1' => 'value_1']],
|
||||||
|
], $this->parser->parse($yaml));
|
||||||
|
}
|
||||||
|
|
||||||
public function testMergeKeysWhenMappingsAreParsedAsObjects()
|
public function testMergeKeysWhenMappingsAreParsedAsObjects()
|
||||||
{
|
{
|
||||||
$yaml = <<<YAML
|
$yaml = <<<YAML
|
||||||
@ -2287,7 +2315,7 @@ YAML;
|
|||||||
parameters:
|
parameters:
|
||||||
abc
|
abc
|
||||||
|
|
||||||
# Comment
|
# Comment
|
||||||
YAML;
|
YAML;
|
||||||
|
|
||||||
$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));
|
$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));
|
||||||
|
Reference in New Issue
Block a user