Skip to content

Commit 05ffb6f

Browse files
committed
bug symfony#25325 [Yaml] do not evaluate PHP constant names (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] do not evaluate PHP constant names | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#25307 | License | MIT | Doc PR | PHP constant identifiers must be strings anyway. Thus, we only need to parse quoted strings, but do not have to evaluate the data types. Commits ------- 956287b do not evaluate PHP constant names
2 parents 5d7576c + 956287b commit 05ffb6f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
707707
return;
708708
case 0 === strpos($scalar, '!php/const'):
709709
if (self::$constantSupport) {
710-
if (defined($const = self::parseScalar(substr($scalar, 11)))) {
710+
$i = 0;
711+
if (defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
711712
return constant($const);
712713
}
713714

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function getTestsForParsePhpConstants()
5858
array('!php/const PHP_INT_MAX', PHP_INT_MAX),
5959
array('[!php/const PHP_INT_MAX]', array(PHP_INT_MAX)),
6060
array('{ foo: !php/const PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
61+
array('!php/const NULL', null),
6162
);
6263
}
6364

@@ -82,10 +83,22 @@ public function testParsePhpConstantThrowsExceptionOnInvalidType()
8283
/**
8384
* @group legacy
8485
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
86+
* @dataProvider getTestsForParseLegacyPhpConstants
8587
*/
86-
public function testDeprecatedConstantTag()
88+
public function testDeprecatedConstantTag($yaml, $expectedValue)
8789
{
88-
Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_CONSTANT);
90+
$this->assertSame($expectedValue, Inline::parse($yaml, Yaml::PARSE_CONSTANT));
91+
}
92+
93+
public function getTestsForParseLegacyPhpConstants()
94+
{
95+
return array(
96+
array('!php/const:Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT),
97+
array('!php/const:PHP_INT_MAX', PHP_INT_MAX),
98+
array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)),
99+
array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
100+
array('!php/const:NULL', null),
101+
);
89102
}
90103

91104
/**

0 commit comments

Comments
 (0)