8000 [Yaml] parse PHP constants in mapping keys · symfony/symfony@5ea41c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ea41c1

Browse files
committed
[Yaml] parse PHP constants in mapping keys
1 parent aef39bc commit 5ea41c1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function doParse($value, $flags)
208208
$this->refs[$isRef] = end($data);
209209
}
210210
} elseif (
211-
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
211+
self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?(?:![^\s]++\s++)?[^ \'"\[\{!].*?) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
212212
&& (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))
213213
) {
214214
if ($context && 'sequence' == $context) {

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,9 +1773,36 @@ public function testParserCleansUpReferencesBetweenRuns()
17731773
YAML;
17741774
$this->parser->parse($yaml);
17751775
}
1776+
1777+
public function testPhpConstantTagMappingKey()
1778+
{
1779+
$yaml = <<<YAML
1780+
transitions:
1781+
!php/const:Symfony\Component\Yaml\Tests\B::FOO:
1782+
from:
1783+
- !php/const:Symfony\Component\Yaml\Tests\B::BAR
1784+
to: !php/const:Symfony\Component\Yaml\Tests\B::BAZ
1785+
YAML;
1786+
$expected = array(
1787+
'transitions' => array(
1788+
'foo' => array(
1789+
'from' => array(
1790+
'bar',
1791+
),
1792+
'to' => 'baz',
1793+
),
1794+
),
1795+
);
1796+
1797+
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
1798+
}
17761799
}
17771800

17781801
class B
17791802
{
17801803
public $b = 'foo';
1804+
1805+
const FOO = 'foo';
1806+
const BAR = 'bar';
1807+
const BAZ = 'baz';
17811808
}

0 commit comments

Comments
 (0)
0