From d5894a4ff9dc1de758273f4bdb263e9ba41e6a01 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 9 Sep 2019 13:28:51 +0200 Subject: [PATCH] properly catch legacy tag syntax usages --- src/Symfony/Component/Yaml/Inline.php | 8 ++++++-- src/Symfony/Component/Yaml/Tests/ParserTest.php | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index bfe2fd3516..b9b399937b 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -670,7 +670,7 @@ class Inline $nextOffset += strspn($value, ' ', $nextOffset); // Is followed by a scalar and is a built-in tag - if ($tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) { + if ('' !== $tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) { // Manage in {@link self::evaluateScalar()} return null; } @@ -678,10 +678,14 @@ class Inline $i = $nextOffset; // Built-in tags - if ($tag && '!' === $tag[0]) { + if ('' !== $tag && '!' === $tag[0]) { throw new ParseException(sprintf('The built-in tag "!%s" is not implemented.', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename); } + if ('' !== $tag && !isset($value[$i])) { + throw new ParseException(sprintf('Missing value for tag "%s".', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename); + } + if ('' === $tag || Yaml::PARSE_CUSTOM_TAGS & $flags) { return $tag; } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 366902a864..00b383e7f3 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Yaml\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Tag\TaggedValue; use Symfony\Component\Yaml\Yaml; @@ -1841,6 +1842,14 @@ YAML; $this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT)); } + public function testDeprecatedPhpConstantSyntax() + { + $this->expectException(ParseException::class); + $this->expectExceptionMessage('Missing value for tag "php/const:App\Kernel::SEMART_VERSION" at line 1 (near "!php/const:App\Kernel::SEMART_VERSION").'); + + $this->parser->parse('!php/const:App\Kernel::SEMART_VERSION', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT); + } + public function testMergeKeysWhenMappingsAreParsedAsObjects() { $yaml = <<