Skip to content
Permalink
Browse files

Validator::validateInteger() returns false when integer is too big

  • Loading branch information
dg committed Mar 24, 2020
1 parent 99fd626 commit d82305cdc989dbf75160e54d53c2f2cab2c985bf
Showing with 6 additions and 5 deletions.
  1. +5 −4 src/Forms/Validator.php
  2. +1 −1 tests/Forms/Controls.TestBase.validators.phpt
@@ -290,10 +290,11 @@ public static function validateNumeric(IControl $control): bool
*/
public static function validateInteger(IControl $control): bool
{
if (Validators::isNumericInt($value = $control->getValue())) {
if (!is_float($tmp = $value * 1)) { // bigint leave as string
$control->setValue($tmp);
}
if (
Validators::isNumericInt($value = $control->getValue())
&& !is_float($tmp = $value * 1) // too big for int?
) {
$control->setValue($tmp);
return true;
}
return false;
@@ -196,7 +196,7 @@ test(function () {
Assert::same('123.5', $control->value);

$control->value = PHP_INT_MAX . PHP_INT_MAX;
Assert::true(Validator::validateInteger($control));
Assert::false(Validator::validateInteger($control));
Assert::same(PHP_INT_MAX . PHP_INT_MAX, $control->value);
});

0 comments on commit d82305c

Please sign in to comment.
You can’t perform that action at this time.