Skip to content

Commit

Permalink
bug #35318 [Yaml] fix PHP const mapping keys using the inline notatio…
Browse files Browse the repository at this point in the history
…n (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Yaml] fix PHP const mapping keys using the inline notation

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35179
| License       | MIT
| Doc PR        |

Commits
-------

45461c7 fix PHP const mapping keys using the inline notation
  • Loading branch information
fabpot committed Jan 13, 2020
2 parents 764c91b + 45461c7 commit db3134e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -504,6 +504,11 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = []
$isKeyQuoted = \in_array($mapping[$i], ['"', "'"], true);
$key = self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true);

if ('!php/const' === $key) {
$key .= self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true);
$key = self::evaluateScalar($key, $flags);
}

if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Expand Up @@ -58,6 +58,7 @@ public function getTestsForParsePhpConstants()
['!php/const PHP_INT_MAX', PHP_INT_MAX],
['[!php/const PHP_INT_MAX]', [PHP_INT_MAX]],
['{ foo: !php/const PHP_INT_MAX }', ['foo' => PHP_INT_MAX]],
['{ !php/const PHP_INT_MAX: foo }', [PHP_INT_MAX => 'foo']],
['!php/const NULL', null],
];
}
Expand Down Expand Up @@ -93,6 +94,7 @@ public function getTestsForParseLegacyPhpConstants()
['!php/const:PHP_INT_MAX', PHP_INT_MAX],
['[!php/const:PHP_INT_MAX]', [PHP_INT_MAX]],
['{ foo: !php/const:PHP_INT_MAX }', ['foo' => PHP_INT_MAX]],
['{ !php/const:PHP_INT_MAX: foo }', [PHP_INT_MAX => 'foo']],
['!php/const:NULL', null],
];
}
Expand Down

0 comments on commit db3134e

Please sign in to comment.