From 0513bbe5606c41142b53185331f7c18e3d11ae9f Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Thu, 28 Dec 2017 17:35:19 +0800 Subject: [PATCH] Fix toBn hex string problem. --- src/Utils.php | 4 ++-- test/unit/UtilsTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index 9abd5dc..6cbd1f9 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -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 { diff --git a/test/unit/UtilsTest.php b/test/unit/UtilsTest.php index de95360..18863c8 100644 --- a/test/unit/UtilsTest.php +++ b/test/unit/UtilsTest.php @@ -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'); } } \ No newline at end of file