From 7f6a0d8ef254f3692dff8e04f915d55575ad75aa Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 4 Aug 2017 17:42:05 +0200 Subject: [PATCH] remove legacy php/const and php/object tag support --- src/Symfony/Component/Yaml/Inline.php | 41 +------------ .../Component/Yaml/Tests/InlineTest.php | 9 --- .../Component/Yaml/Tests/ParserTest.php | 58 +------------------ 3 files changed, 2 insertions(+), 106 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index a70fd09bea..d2d39b644e 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -554,30 +554,6 @@ class Inline return (string) substr($scalar, 6); case 0 === strpos($scalar, '! '): return substr($scalar, 2); - case 0 === strpos($scalar, '!php/object:'): - if (self::$objectSupport) { - @trigger_error('The !php/object: tag to indicate dumped PHP objects is deprecated since version 3.4 and will be removed in 4.0. Use the !php/object (without the colon) tag instead.', E_USER_DEPRECATED); - - return unserialize(substr($scalar, 12)); - } - - if (self::$exceptionOnInvalidType) { - throw new ParseException('Object support when parsing a YAML file has been disabled.'); - } - - return; - case 0 === strpos($scalar, '!!php/object:'): - if (self::$objectSupport) { - @trigger_error('The !!php/object: tag to indicate dumped PHP objects is deprecated since version 3.1 and will be removed in 4.0. Use the !php/object (without the colon) tag instead.', E_USER_DEPRECATED); - - return unserialize(substr($scalar, 13)); - } - - if (self::$exceptionOnInvalidType) { - throw new ParseException('Object support when parsing a YAML file has been disabled.'); - } - - return; case 0 === strpos($scalar, '!php/object'): if (self::$objectSupport) { return unserialize(self::parseScalar(substr($scalar, 12))); @@ -587,21 +563,6 @@ class Inline throw new ParseException('Object support when parsing a YAML file has been disabled.'); } - return; - case 0 === strpos($scalar, '!php/const:'): - if (self::$constantSupport) { - @trigger_error('The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.', E_USER_DEPRECATED); - - if (defined($const = substr($scalar, 11))) { - return constant($const); - } - - throw new ParseException(sprintf('The constant "%s" is not defined.', $const)); - } - if (self::$exceptionOnInvalidType) { - throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Have you forgotten to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar)); - } - return; case 0 === strpos($scalar, '!php/const'): if (self::$constantSupport) { @@ -690,7 +651,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], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 0 === strpos($tag, 'php/const:') || 0 === strpos($tag, 'php/object:'))) { + if ($tag && (!isset($value[$nextOffset]) || !in_array($value[$nextOffset], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) { // Manage in {@link self::evaluateScalar()} return; } diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index e6a4d9a35d..b1a4c1ccb5 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -74,15 +74,6 @@ class InlineTest extends TestCase Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); } - /** - * @group legacy - * @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead. - */ - public function testDeprecatedConstantTag() - { - Inline::parse('!php/const:PHP_INT_MAX', Yaml::PARSE_CONSTANT); - } - /** * @dataProvider getTestsForDump */ diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 2f18c2b69b..c8142a46df 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -441,39 +441,12 @@ EOF; public function testObjectSupportDisabledButNoExceptions() { $input = <<<'EOF' -foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} +foo: !php/object O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";} bar: 1 EOF; $this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects'); } - /** - * @group legacy - * @dataProvider deprecatedObjectValueProvider - */ - public function testObjectSupportEnabledWithDeprecatedTag($yaml) - { - $this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($yaml, Yaml::PARSE_OBJECT), '->parse() is able to parse objects'); - } - - public function deprecatedObjectValueProvider() - { - return array( - array( - <<assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT)); } - - /** - * @group legacy - * @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead. - * @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead. - * @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead. - */ - public function testDeprecatedPhpConstantTagMappingKey() - { - $yaml = << array( - 'foo' => array( - 'from' => array( - 'bar', - ), - 'to' => 'baz', - ), - ), - ); - - $this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT)); - } } class B