From b3be7ea75b64d96e088b4427f236775ae6327905 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 29 Mar 2017 15:41:10 +0200 Subject: [PATCH] Validators::isInRange() ignores NULL --- src/Utils/Validators.php | 3 ++- tests/Utils/Validators.isInRange().phpt | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Utils/Validators.php b/src/Utils/Validators.php index 64f883592..a67661faa 100644 --- a/src/Utils/Validators.php +++ b/src/Utils/Validators.php @@ -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]); } diff --git a/tests/Utils/Validators.isInRange().phpt b/tests/Utils/Validators.isInRange().phpt index db42f6ed4..53980d2fa 100644 --- a/tests/Utils/Validators.isInRange().phpt +++ b/tests/Utils/Validators.isInRange().phpt @@ -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']));