Skip to content

Commit

Permalink
Merge pull request #54 from arokettu/avoid-false-return-from-substr
Browse files Browse the repository at this point in the history
Avoid false return from substr() in  PHP < 8.0
  • Loading branch information
froschdesign authored Aug 20, 2021
2 parents 5e85a8f + 168bebd commit 78adb53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Validator/IsFloat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/Validator/IsFloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 78adb53

Please sign in to comment.