bug #33517 [Yaml] properly catch legacy tag syntax usages (xabbuh)
This PR was merged into the 4.3 branch.
Discussion
----------
[Yaml] properly catch legacy tag syntax usages
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #25534
| License | MIT
| Doc PR |
Commits
-------
d5894a4ff9
properly catch legacy tag syntax usages
This commit is contained in:
commit
5914a1fdef
@ -670,7 +670,7 @@ class Inline
|
|||||||
$nextOffset += strspn($value, ' ', $nextOffset);
|
$nextOffset += strspn($value, ' ', $nextOffset);
|
||||||
|
|
||||||
// Is followed by a scalar and is a built-in tag
|
// 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()}
|
// Manage in {@link self::evaluateScalar()}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -678,10 +678,14 @@ class Inline
|
|||||||
$i = $nextOffset;
|
$i = $nextOffset;
|
||||||
|
|
||||||
// Built-in tags
|
// 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);
|
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) {
|
if ('' === $tag || Yaml::PARSE_CUSTOM_TAGS & $flags) {
|
||||||
return $tag;
|
return $tag;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Yaml\Tests;
|
namespace Symfony\Component\Yaml\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
use Symfony\Component\Yaml\Parser;
|
use Symfony\Component\Yaml\Parser;
|
||||||
use Symfony\Component\Yaml\Tag\TaggedValue;
|
use Symfony\Component\Yaml\Tag\TaggedValue;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
@ -1841,6 +1842,14 @@ YAML;
|
|||||||
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
|
$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()
|
public function testMergeKeysWhenMappingsAreParsedAsObjects()
|
||||||
{
|
{
|
||||||
$yaml = <<<YAML
|
$yaml = <<<YAML
|
||||||
|
Reference in New Issue
Block a user