prevent notice for invalid octal numbers on PHP 7.4
This commit is contained in:
parent
cfa048c804
commit
92bc19fd0c
@ -759,15 +759,21 @@ class Inline
|
||||
|
||||
switch (true) {
|
||||
case ctype_digit($scalar):
|
||||
$raw = $scalar;
|
||||
if ('0' === $scalar[0]) {
|
||||
return octdec(preg_replace('/[^0-7]/', '', $scalar));
|
||||
}
|
||||
|
||||
$cast = (int) $scalar;
|
||||
|
||||
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
|
||||
return ($scalar === (string) $cast) ? $cast : $scalar;
|
||||
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
|
||||
$raw = $scalar;
|
||||
if ('0' === $scalar[1]) {
|
||||
return -octdec(preg_replace('/[^0-7]/', '', substr($scalar, 1)));
|
||||
}
|
||||
|
||||
$cast = (int) $scalar;
|
||||
|
||||
return '0' == $scalar[1] ? -octdec(substr($scalar, 1)) : (($raw === (string) $cast) ? $cast : $raw);
|
||||
return ($scalar === (string) $cast) ? $cast : $scalar;
|
||||
case is_numeric($scalar):
|
||||
case Parser::preg_match(self::getHexRegex(), $scalar):
|
||||
$scalar = str_replace('_', '', $scalar);
|
||||
|
@ -842,4 +842,14 @@ class InlineTest extends TestCase
|
||||
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testParsePositiveOctalNumberContainingInvalidDigits()
|
||||
{
|
||||
self::assertSame(342391, Inline::parse('0123456789'));
|
||||
}
|
||||
|
||||
public function testParseNegativeOctalNumberContainingInvalidDigits()
|
||||
{
|
||||
self::assertSame(-342391, Inline::parse('-0123456789'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user