Skip to content

[Yaml] Remove deprecated code #41360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
case 0 === strncmp($scalar, '!php/object', 11):
if (self::$objectSupport) {
if (!isset($scalar[12])) {
trigger_deprecation('symfony/yaml', '5.1', 'Using the !php/object tag without a value is deprecated.');

return false;
throw new ParseException('Missing value for tag "!php/object".', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}

return unserialize(self::parseScalar(substr($scalar, 12)));
Expand All @@ -617,9 +615,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
case 0 === strncmp($scalar, '!php/const', 10):
if (self::$constantSupport) {
if (!isset($scalar[11])) {
trigger_deprecation('symfony/yaml', '5.1', 'Using the !php/const tag without a value is deprecated.');

return '';
throw new ParseException('Missing value for tag "!php/const".', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}

$i = 0;
Expand Down Expand Up @@ -660,22 +656,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer

switch (true) {
case ctype_digit($scalar):
if (preg_match('/^0[0-7]+$/', $scalar)) {
trigger_deprecation('symfony/yaml', '5.1', 'Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0.');

return octdec($scalar);
}

$cast = (int) $scalar;

return ($scalar === (string) $cast) ? $cast : $scalar;
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
if (preg_match('/^-0[0-7]+$/', $scalar)) {
trigger_deprecation('symfony/yaml', '5.1', 'Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0.');

return -octdec(substr($scalar, 1));
}

$cast = (int) $scalar;

return ($scalar === (string) $cast) ? $cast : $scalar;
Expand Down
77 changes: 29 additions & 48 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,92 +757,73 @@ public function getTestsForOctalNumbers()
}

/**
* @group legacy
* @dataProvider getTestsForOctalNumbersYaml11Notation
*/
public function testParseOctalNumbersYaml11Notation(int $expected, string $yaml)
public function testParseOctalNumbersYaml11Notation(string $expected, string $yaml)
{
$this->expectDeprecation('Since symfony/yaml 5.1: Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0.');

self::assertSame($expected, Inline::parse($yaml));
}

public function getTestsForOctalNumbersYaml11Notation()
{
return [
'positive octal number' => [28, '034'],
'positive octal number with separator' => [1243, '0_2_3_3_3'],
'negative octal number' => [-28, '-034'],
'positive octal number' => ['034', '034'],
'positive octal number with separator' => ['02333', '0_2_3_3_3'],
'negative octal number' => ['-034', '-034'],
'invalid positive octal number' => ['0123456789', '0123456789'],
'invalid negative octal number' => ['-0123456789', '-0123456789'],
];
}

/**
* @dataProvider phpObjectTagWithEmptyValueProvider
*
* @group legacy
*/
public function testPhpObjectWithEmptyValue($expected, $value)
public function testPhpObjectWithEmptyValue(string $value)
{
$this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/object tag without a value is deprecated.');
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Missing value for tag "!php/object" at line 1 (near "!php/object").');

$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT));
Inline::parse($value, Yaml::PARSE_OBJECT);
}

public function phpObjectTagWithEmptyValueProvider()
{
return [
[false, '!php/object'],
[false, '!php/object '],
[false, '!php/object '],
[[false], '[!php/object]'],
[[false], '[!php/object ]'],
[[false, 'foo'], '[!php/object , foo]'],
['!php/object'],
['!php/object '],
['!php/object '],
['[!php/object]'],
['[!php/object ]'],
['[!php/object , foo]'],
];
}

/**
* @dataProvider phpConstTagWithEmptyValueProvider
*
* @group legacy
*/
public function testPhpConstTagWithEmptyValue($expected, $value)
public function testPhpConstTagWithEmptyValue(string $value)
{
$this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/const tag without a value is deprecated.');
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Missing value for tag "!php/const" at line 1 (near "!php/const").');

$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
Inline::parse($value, Yaml::PARSE_CONSTANT);
}

public function phpConstTagWithEmptyValueProvider()
{
return [
['', '!php/const'],
['', '!php/const '],
['', '!php/const '],
[[''], '[!php/const]'],
[[''], '[!php/const ]'],
[['', 'foo'], '[!php/const , foo]'],
[['' => 'foo'], '{!php/const: foo}'],
[['' => 'foo'], '{!php/const : foo}'],
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
['!php/const'],
['!php/const '],
['!php/const '],
['[!php/const]'],
['[!php/const ]'],
['[!php/const , foo]'],
['{!php/const: foo}'],
['{!php/const : foo}'],
['{!php/const : foo, bar: ccc}'],
];
}

/**
* @group legacy
*/
public function testParsePositiveOctalNumberContainingInvalidDigits()
{
self::assertSame('0123456789', Inline::parse('0123456789'));
}

/**
* @group legacy
*/
public function testParseNegativeOctalNumberContainingInvalidDigits()
{
self::assertSame('-0123456789', Inline::parse('-0123456789'));
}

public function testParseCommentNotPrefixedBySpaces()
{
self::assertSame('foo', Inline::parse('"foo"#comment'));
Expand Down