bug #35318 [Yaml] fix PHP const mapping keys using the inline notation (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
-------

45461c73bf fix PHP const mapping keys using the inline notation
This commit is contained in:
Fabien Potencier 2020-01-13 14:54:16 +01:00
commit db3134eba4
2 changed files with 7 additions and 0 deletions

View File

@ -504,6 +504,11 @@ class Inline
$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;
}

View File

@ -58,6 +58,7 @@ class InlineTest extends TestCase
['!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],
];
}
@ -93,6 +94,7 @@ class InlineTest extends TestCase
['!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],
];
}