Commit d6b797e2 by Qiang Xue

Fixes #5252: Null values are not properly handled by `RangeValidator`

parent d4ceeb2d
...@@ -4,6 +4,7 @@ Yii Framework 2 Change Log ...@@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.0 under development 2.0.0 under development
----------------------- -----------------------
- Bug #5252: Null values are not properly handled by `RangeValidator` (githubjeka, qiangxue)
- Bug #5260: `yii\i18n\Formatter::decimalSeparator` and `yii\i18n\Formatter::thousandSeparator` where not configurable when intl is not installed (execut, cebe) - Bug #5260: `yii\i18n\Formatter::decimalSeparator` and `yii\i18n\Formatter::thousandSeparator` where not configurable when intl is not installed (execut, cebe)
- Bug #5314: Fixed typo in the implementation of `yii\web\Session::getHasSessionId()` (qiangxue) - Bug #5314: Fixed typo in the implementation of `yii\web\Session::getHasSessionId()` (qiangxue)
- Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe) - Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe)
......
...@@ -66,7 +66,7 @@ class RangeValidator extends Validator ...@@ -66,7 +66,7 @@ class RangeValidator extends Validator
$in = true; $in = true;
foreach ((array)$value as $v) { foreach ((is_array($value) ? $value : [$value]) as $v) {
if (!in_array($v, $this->range, $this->strict)) { if (!in_array($v, $this->range, $this->strict)) {
$in = false; $in = false;
break; break;
......
...@@ -41,6 +41,17 @@ class RangeValidatorTest extends TestCase ...@@ -41,6 +41,17 @@ class RangeValidatorTest extends TestCase
$this->assertTrue($val->validate("5")); $this->assertTrue($val->validate("5"));
} }
public function testValidateValueEmpty()
{
$val = new RangeValidator(['range' => range(10, 20, 1), 'skipOnEmpty' => false]);
$this->assertFalse($val->validate(null)); //row RangeValidatorTest.php:101
$this->assertFalse($val->validate('0'));
$this->assertFalse($val->validate(0));
$this->assertFalse($val->validate(''));
$val->allowArray = true;
$this->assertTrue($val->validate([]));
}
public function testValidateArrayValue() public function testValidateArrayValue()
{ {
$val = new RangeValidator(['range' => range(1, 10, 1)]); $val = new RangeValidator(['range' => range(1, 10, 1)]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment