mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-15 03:38:01 +01:00
Fixes #15553: Fixed yii\validators\NumberValidator incorrectly validate resource
This commit is contained in:
committed by
Alexander Makarov
parent
dbcb66b87a
commit
eb57d4191c
@@ -81,7 +81,7 @@ class NumberValidator extends Validator
|
||||
public function validateAttribute($model, $attribute)
|
||||
{
|
||||
$value = $model->$attribute;
|
||||
if (is_array($value) || (is_object($value) && !method_exists($value, '__toString'))) {
|
||||
if ($this->isNotNumber($value)) {
|
||||
$this->addError($model, $attribute, $this->message);
|
||||
return;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class NumberValidator extends Validator
|
||||
*/
|
||||
protected function validateValue($value)
|
||||
{
|
||||
if (is_array($value) || is_object($value)) {
|
||||
if ($this->isNotNumber($value)) {
|
||||
return [Yii::t('yii', '{attribute} is invalid.'), []];
|
||||
}
|
||||
$pattern = $this->integerOnly ? $this->integerPattern : $this->numberPattern;
|
||||
@@ -118,6 +118,16 @@ class NumberValidator extends Validator
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @param mixed $value the data value to be checked.
|
||||
*/
|
||||
private function isNotNumber($value)
|
||||
{
|
||||
return is_array($value)
|
||||
|| (is_object($value) && !method_exists($value, '__toString'))
|
||||
|| (!is_object($value) && !is_scalar($value) && !is_null($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user