From 45461c73bf78431c4f61933a92eee1422351f522 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 13 Jan 2020 09:00:59 +0100 Subject: [PATCH] fix PHP const mapping keys using the inline notation --- src/Symfony/Component/Yaml/Inline.php | 5 +++++ src/Symfony/Component/Yaml/Tests/InlineTest.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index aef68c7b2fa1..73aba3cb8b0d 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -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; } diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 3f3b913f7b6f..54372d69505b 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -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], ]; } @@ -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], ]; }