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 39cd392
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8216,7 +8216,7 @@ private function getNumberFromImage($numberRepresentation)
return bindec(substr($numberRepresentation, 2));

default:
if (substr($numberRepresentation, 0, 1) === '0') {
if (preg_match('/^0+(oO)?\d/', $numberRepresentation)) {
return octdec(preg_replace('/^0+(oO)?/', '', $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
@@ -0,0 +1,6 @@
<?php

class testLiteralWithZeroFloatValue
{
private float $amount = 0.00;
}

0 comments on commit 39cd392

Please sign in to comment.