Skip to content

Commit

Permalink
Validator::validateInteger() returns false when integer is too big
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 24, 2020
1 parent 35f9b84 commit c65ced6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/Forms/Validator.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/Controls.TestBase.validators.phpt
Expand Up @@ -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);
});

Expand Down

0 comments on commit c65ced6

Please sign in to comment.