From 0d0c78600b3a37bea229173c5ee910d84449893e Mon Sep 17 00:00:00 2001 From: Anton Smirnov Date: Fri, 13 Aug 2021 20:36:34 +0300 Subject: [PATCH 1/2] Add some small values to the test Signed-off-by: Anton Smirnov --- test/Validator/IsFloatTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Validator/IsFloatTest.php b/test/Validator/IsFloatTest.php index 0073f6e1..e7a84ae1 100644 --- a/test/Validator/IsFloatTest.php +++ b/test/Validator/IsFloatTest.php @@ -73,7 +73,7 @@ public function floatAndIntegerProvider() $trueArray = []; $testingLocales = ['ar', 'bn', 'de', 'dz', 'en', 'fr-CH', 'ja', 'ks', 'ml-IN', 'mr', 'my', 'ps', 'ru']; $testingExamples = [1000, -2000, +398.00, 0.04, -0.5, .6, -.70, 8E10, -9.3456E-2, 10.23E6, - 123.1234567890987654321]; + 123.1234567890987654321, 1, 13, -3]; //Loop locales and examples for a more thorough set of "true" test data foreach ($testingLocales as $locale) { From 168bebd600b0223ca0720bb831632e33f16ed2b2 Mon Sep 17 00:00:00 2001 From: Anton Smirnov Date: Fri, 13 Aug 2021 20:45:05 +0300 Subject: [PATCH 2/2] Check string length before getting a substring to avoid false return Signed-off-by: Anton Smirnov --- src/Validator/IsFloat.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Validator/IsFloat.php b/src/Validator/IsFloat.php index 0c29774a..07556ec2 100644 --- a/src/Validator/IsFloat.php +++ b/src/Validator/IsFloat.php @@ -235,7 +235,9 @@ public function isValid($value) // No strrpos() in wrappers yet. ICU 4.x doesn't have grouping size for // everything. ICU 52 has 3 for ALL locales. $groupSize = $formatter->getAttribute(NumberFormatter::GROUPING_SIZE) ?: 3; - $lastStringGroup = $this->wrapper->substr($value, -$groupSize); + $lastStringGroup = $this->wrapper->strlen($value) > $groupSize ? + $this->wrapper->substr($value, -$groupSize) : + $value; if ((preg_match($lnumSearch, $unGroupedValue) || preg_match($dnumSearch, $unGroupedValue)