Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  [Validator] RangeTest: fix expected deprecation
  [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
  • Loading branch information
fabpot committed Aug 13, 2020
2 parents 244ba10 + c3a7761 commit 9ac517c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ private function doParse(string $value, int $flags)
$this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags)
);
} else {
if (isset($values['leadspaces'])
&& self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
if (
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
$block = $values['value'];
Expand Down
30 changes: 29 additions & 1 deletion Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,34 @@ public function testDeprecatedPhpConstantSyntax()
$this->parser->parse('!php/const:App\Kernel::SEMART_VERSION', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT);
}

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()
{
$yaml = <<<YAML
Expand Down Expand Up @@ -2338,7 +2366,7 @@ public function testMultiLineComment()
parameters:
abc
# Comment
# Comment
YAML;

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

0 comments on commit 9ac517c

Please sign in to comment.