From 1d47285b8b4c1c1b220250301816b572a2586411 Mon Sep 17 00:00:00 2001 From: srdante Date: Sat, 26 Feb 2022 03:15:44 -0300 Subject: [PATCH] Fix preg match & testings --- src/Utils.php | 2 +- test/unit/OptionalQuantityFormatterTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index be80c9d..8883c2b 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -529,7 +529,7 @@ class Utils $number = str_replace('-', '', $number, $count); $negative1 = new BigNumber(-1); } - if (self::isZeroPrefixed($number) || preg_match('/[a-f]+/', $number) === 1) { + if (self::isZeroPrefixed($number) || preg_match('/^[0-9a-f]+$/i', $number) === 1) { $number = self::stripZero($number); $bn = new BigNumber($number, 16); } elseif (empty($number)) { diff --git a/test/unit/OptionalQuantityFormatterTest.php b/test/unit/OptionalQuantityFormatterTest.php index 0f0f9ec..6ee009f 100644 --- a/test/unit/OptionalQuantityFormatterTest.php +++ b/test/unit/OptionalQuantityFormatterTest.php @@ -55,6 +55,8 @@ class OptionalQuantityFormatterTest extends TestCase $this->assertEquals('latest', $formatter->format('latest')); $this->assertEquals('earliest', $formatter->format('earliest')); $this->assertEquals('pending', $formatter->format('pending')); - $this->assertEquals('0x0', $formatter->format('hello')); + + $this->expectExceptionMessage('toBn number must be valid hex string.'); + $formatter->format('hello'); } } \ No newline at end of file