Skip to content

Commit

Permalink
Validators::isInRange() ignores NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 29, 2017
1 parent 1319046 commit b3be7ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Utils/Validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ public static function isList($value): bool
*/
public static function isInRange($value, array $range): bool
{
return (!isset($range[0]) || $range[0] === '' || $value >= $range[0])
return $value !== NULL
&& (!isset($range[0]) || $range[0] === '' || $value >= $range[0])
&& (!isset($range[1]) || $range[1] === '' || $value <= $range[1]);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Utils/Validators.isInRange().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ Assert::true(Validators::isInRange(-1, ['', 2]));

Assert::true(Validators::isInRange(1, [-1, NULL]));
Assert::true(Validators::isInRange(1, [-1, '']));

Assert::false(Validators::isInRange(NULL, [0, 1]));
Assert::false(Validators::isInRange(NULL, ['0', 'b']));

0 comments on commit b3be7ea

Please sign in to comment.