Skip to content

Commit c3a7761

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: [Yaml] Fix for #36624; Allow PHP constant as first key in block Use PHPUnit 9.3 on php 8. fix mapping errors from unmapped forms [Validator] Add target guards for Composite nested constraints
2 parents f5f122c + 079faef commit c3a7761

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

Parser.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ private function doParse(string $value, int $flags)
176176
$this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags)
177177
);
178178
} else {
179-
if (isset($values['leadspaces'])
180-
&& self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
179+
if (
180+
isset($values['leadspaces'])
181+
&& (
182+
'!' === $values['value'][0]
183+
|| self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
184+
)
181185
) {
182186
// this is a compact notation element, add to next block and parse
183187
$block = $values['value'];

Tests/ParserTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,34 @@ public function testDeprecatedPhpConstantSyntax()
20772077
$this->parser->parse('!php/const:App\Kernel::SEMART_VERSION', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT);
20782078
}
20792079

2080+
public function testPhpConstantTagMappingAsScalarKey()
2081+
{
2082+
$yaml = <<<YAML
2083+
map1:
2084+
- foo: 'value_0'
2085+
!php/const 'Symfony\Component\Yaml\Tests\B::BAR': 'value_1'
2086+
map2:
2087+
- !php/const 'Symfony\Component\Yaml\Tests\B::FOO': 'value_0'
2088+
bar: 'value_1'
2089+
YAML;
2090+
$this->assertSame([
2091+
'map1' => [['foo' => 'value_0', 'bar' => 'value_1']],
2092+
'map2' => [['foo' => 'value_0', 'bar' => 'value_1']],
2093+
], $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
2094+
}
2095+
2096+
public function testTagMappingAsScalarKey()
2097+
{
2098+
$yaml = <<<YAML
2099+
map1:
2100+
- !!str 0: 'value_0'
2101+
!!str 1: 'value_1'
2102+
YAML;
2103+
$this->assertSame([
2104+
'map1' => [['0' => 'value_0', '1' => 'value_1']],
2105+
], $this->parser->parse($yaml));
2106+
}
2107+
20802108
public function testMergeKeysWhenMappingsAreParsedAsObjects()
20812109
{
20822110
$yaml = <<<YAML
@@ -2339,7 +2367,7 @@ public function testMultiLineComment()
23392367
parameters:
23402368
abc
23412369
2342-
# Comment
2370+
# Comment
23432371
YAML;
23442372

23452373
$this->assertSame(['parameters' => 'abc'], $this->parser->parse($yaml));

0 commit comments

Comments
 (0)