Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float parsing for number starting with 0. #691

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}