Fix toBn hex string problem.

This commit is contained in:
sc0Vu 2017-12-28 17:35:19 +08:00
parent 1766e37a66
commit 0513bbe560
2 changed files with 6 additions and 2 deletions

View File

@ -118,7 +118,7 @@ class Utils
if (!is_string($value)) {
throw new InvalidArgumentException('The value to zeroPrefixed function must be string.');
}
return (strpos($value, '0x') === 0) ;
return (strpos($value, '0x') === 0);
}
/**
@ -392,7 +392,7 @@ class Utils
} elseif (is_string($number)) {
$number = mb_strtolower($number);
if (self::isZeroPrefixed($number)) {
if (self::isZeroPrefixed($number) || preg_match('/[a-f]+/', $number) === 1) {
$number = self::stripZero($number);
$bn = new BigNumber($number, 16);
} else {

View File

@ -406,5 +406,9 @@ class UtilsTest extends TestCase
$bn = Utils::toBn(0x12);
$this->assertEquals($bn->toString(), '18');
$bn = Utils::toBn('ae');
$this->assertEquals($bn->toString(), '174');
}
}