Prevent parsing invalid octal digits as octal numbers
This commit is contained in:
parent
8e34978e4e
commit
c7dcd82f03
@ -759,16 +759,16 @@ class Inline
|
|||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case ctype_digit($scalar):
|
case ctype_digit($scalar):
|
||||||
if ('0' === $scalar[0]) {
|
if (preg_match('/^0[0-7]+$/', $scalar)) {
|
||||||
return octdec(preg_replace('/[^0-7]/', '', $scalar));
|
return octdec($scalar);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cast = (int) $scalar;
|
$cast = (int) $scalar;
|
||||||
|
|
||||||
return ($scalar === (string) $cast) ? $cast : $scalar;
|
return ($scalar === (string) $cast) ? $cast : $scalar;
|
||||||
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
|
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
|
||||||
if ('0' === $scalar[1]) {
|
if (preg_match('/^-0[0-7]+$/', $scalar)) {
|
||||||
return -octdec(preg_replace('/[^0-7]/', '', substr($scalar, 1)));
|
return -octdec(substr($scalar, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
$cast = (int) $scalar;
|
$cast = (int) $scalar;
|
||||||
|
@ -853,11 +853,11 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
public function testParsePositiveOctalNumberContainingInvalidDigits()
|
public function testParsePositiveOctalNumberContainingInvalidDigits()
|
||||||
{
|
{
|
||||||
self::assertSame(342391, Inline::parse('0123456789'));
|
self::assertSame('0123456789', Inline::parse('0123456789'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParseNegativeOctalNumberContainingInvalidDigits()
|
public function testParseNegativeOctalNumberContainingInvalidDigits()
|
||||||
{
|
{
|
||||||
self::assertSame(-342391, Inline::parse('-0123456789'));
|
self::assertSame('-0123456789', Inline::parse('-0123456789'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user