Skip to content

Commit b3be7ea

Browse files
committed
Validators::isInRange() ignores NULL
1 parent 1319046 commit b3be7ea

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Utils/Validators.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ public static function isList($value): bool
238238
*/
239239
public static function isInRange($value, array $range): bool
240240
{
241-
return (!isset($range[0]) || $range[0] === '' || $value >= $range[0])
241+
return $value !== NULL
242+
&& (!isset($range[0]) || $range[0] === '' || $value >= $range[0])
242243
&& (!isset($range[1]) || $range[1] === '' || $value <= $range[1]);
243244
}
244245

tests/Utils/Validators.isInRange().phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ Assert::true(Validators::isInRange(-1, ['', 2]));
2929

3030
Assert::true(Validators::isInRange(1, [-1, NULL]));
3131
Assert::true(Validators::isInRange(1, [-1, '']));
32+
33+
Assert::false(Validators::isInRange(NULL, [0, 1]));
34+
Assert::false(Validators::isInRange(NULL, ['0', 'b']));

0 commit comments

Comments
 (0)