Skip to content

Commit

Permalink
Fix bug when Multiple is passed an invalid value
Browse files Browse the repository at this point in the history
If you are using `Multiple` to validate, and pass a value that is unsupported by the `%` operator, it will fail instead of creating a validation error. This fixes that bug.
  • Loading branch information
dmjohnsson23 authored and henriquemoody committed Nov 26, 2024
1 parent 967f7b6 commit 9fc0165
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions library/Rules/Multiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

namespace Respect\Validation\Rules;

use function filter_var;

use const FILTER_VALIDATE_INT;

/**
* @author Danilo Benevides <[email protected]>
* @author Henrique Moody <[email protected]>
Expand All @@ -31,6 +35,9 @@ public function __construct(int $multipleOf)
*/
public function validate($input): bool
{
if (filter_var($input, FILTER_VALIDATE_INT) === false) {
return false;
}
if ($this->multipleOf == 0) {
return $input == 0;
}
Expand Down

0 comments on commit 9fc0165

Please sign in to comment.