Skip to content

Commit

Permalink
Fix float parsing for number starting with 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Nov 25, 2023
1 parent a44ec55 commit fe7b834
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8216,8 +8216,8 @@ private function getNumberFromImage($numberRepresentation)
return bindec(substr($numberRepresentation, 2));

default:
if (substr($numberRepresentation, 0, 1) === '0') {
return octdec(preg_replace('/^0+(oO)?/', '', $numberRepresentation));
if (preg_match('/^0+[oO]?(\d+)$/', $numberRepresentation, $match)) {
return octdec($match[1]);
}

return $numberRepresentation;
Expand Down
17 changes: 17 additions & 0 deletions src/test/php/PDepend/Source/AST/ASTLiteralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ public function testLiteralWithNonZeroBinaryIntegerValue()
$this->assertEquals('0b100100100110', $literal->getImage());
}

/**
* testLiteralWithZeroFloatValue
*
* @return void
* @since 2.16.0
* @covers \PDepend\Source\Language\PHP\AbstractPHPParser
*/
public function testLiteralWithZeroFloatValue()
{
$class = $this->getFirstClassForTestCase();
$properties = $class->getProperties();
/** @var ASTProperty $property */
$property = $properties[0];

$this->assertSame(0.0, $property->getDefaultValue());
}

/**
* testLiteralWithCurlyBraceFollowedByCompoundExpression
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @copyright 2008-2017 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @covers \PDepend\Source\Language\PHP\PHPParserVersion81
* @covers \PDepend\Source\Language\PHP\AbstractPHPParser
* @group unittest
* @group php8.1
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/PDepend/TextUI/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public function testDebugErrorDisplay()
$output = ob_get_contents();
ob_end_clean();

Log::setSeverity(0);
Log::setSeverity(2);
$error = file_get_contents($file);
unlink($file);
$streamProperty->setValue(STDERR);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class testLiteralWithZeroFloatValue
{
private float $amount = 0.00;
}

0 comments on commit fe7b834

Please sign in to comment.