fix PHP const mapping keys using the inline notation

This commit is contained in:
Christian Flothmann 2020-01-13 09:00:59 +01:00
parent d1e31a4fe0
commit 45461c73bf
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],
];
}