Skip to content

Commit

Permalink
check if input is a string before checking its length
Browse files Browse the repository at this point in the history
  • Loading branch information
j-koenig authored and philiplb committed Mar 4, 2021
1 parent e52d851 commit b0f3189
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Valdi/Validator/LengthBetween.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class LengthBetween extends AbstractComparator
*/
protected function isValidComparison($value, $parameters)
{
return $this->isAllNumeric($parameters[0], $parameters[1])
return is_string($value)
&& $this->isAllNumeric($parameters[0], $parameters[1])
&& strlen($value) >= $parameters[0]
&& strlen($value) <= $parameters[1];
}
Expand Down
4 changes: 3 additions & 1 deletion src/Valdi/Validator/MaxLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MaxLength extends AbstractComparator
*/
protected function isValidComparison($value, $parameters)
{
return is_numeric($parameters[0]) && strlen($value) <= $parameters[0];
return is_string($value)
&& is_numeric($parameters[0])
&& strlen($value) <= $parameters[0];
}
}
5 changes: 3 additions & 2 deletions src/Valdi/Validator/MinLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class MinLength extends AbstractComparator
*/
protected function isValidComparison($value, $parameters)
{
$length = strlen($value);
return is_numeric($parameters[0]) && $length >= $parameters[0];
return is_string($value)
&& is_numeric($parameters[0])
&& strlen($value) >= $parameters[0];
}
}

0 comments on commit b0f3189

Please sign in to comment.