8000 deprecate parsing octal numbers with invalid formats · symfony/symfony@d3dfffb · GitHub
[go: up one dir, main page]

Skip to content

Commit d3dfffb

Browse files
committed
deprecate parsing octal numbers with invalid formats
1 parent e9be741 commit d3dfffb

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

UPGRADE-5.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,5 @@ Security
164164
Yaml
165165
----
166166

167+
* Deprecate support for parsing invalid octal numbers.
167168
* Deprecated using the `!php/object` and `!php/const` tags without a value.

UPGRADE-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,5 @@ Security
111111
Yaml
112112
----
113113

114+
* Removed support for parsing invalid octal numbers.
114115
* Removed support for using the `!php/object` and `!php/const` tags without a value.

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.1.0
55
-----
66

7+
* Deprecate support for parsing invalid octal numbers.
78
* Added `yaml-lint` binary.
89
* Deprecated using the `!php/object` and `!php/const` tags without a value.
910

src/Symfony/Component/Yaml/Inline.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,20 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
644644
$raw = $scalar;
645645
$cast = (int) $scalar;
646646

647+
if ('0' === $scalar[0] && !Parser::preg_match('/^[0-7]*$/', $scalar)) {
648+
@trigger_error(sprintf('Support for parsing the invalid octal number %s is deprecated since Symfony 5.1.', $scalar), E_USER_DEPRECATED);
649+
}
650+
647651
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
648652
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
649653
$raw = $scalar;
650654
$cast = (int) $scalar;
651655

652-
return '0' == $scalar[1] ? -octdec(substr($scalar, 1)) : (($raw === (string) $cast) ? $cast : $raw);
656+
if ('0' === $scalar[1] && !Parser::preg_match('/^[0-7]*$/', $octal = substr($scalar, 1))) {
657+
@trigger_error(sprintf('Support for parsing the invalid octal number %s is deprecated since Symfony 5.1.', $scalar), E_USER_DEPRECATED);
658+
}
659+
660+
return '0' == $scalar[1] ? -octdec($octal) : (($raw === (string) $cast) ? $cast : $raw);
653661
case is_numeric($scalar):
654662
case Parser::preg_match(self::getHexRegex(), $scalar):
655663
$scalar = str_replace('_', '', $scalar);

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,4 +856,22 @@ public function quotedExclamationMarkProvider()
856856
[['!'], '! ["!"]'],
857857
];
858858
}
859+
860+
/**
861+
* @group legacy
862+
* @expectedDeprecation Support for parsing the invalid octal number 0123456789 is deprecated since Symfony 5.1.
863+
*/
864+
public function testParseInvalidPositiveOctalNumber()
865+
{
866+
self::assertSame(342391, Inline::parse('0123456789'));
867+
}
868+
869+
/**
870+
* @group legacy
871+
* @expectedDeprecation Support for parsing the invalid octal number -0123456789 is deprecated since Symfony 5.1.
872+
*/
873+
public function testParseInvalidNegativeOctalNumber()
874+
{
875+
self::assertSame(-342391, Inline::parse('-0123456789'));
876+
}
859877
}

0 commit comments

Comments
 (0)
0