mirror of
https://github.com/yiisoft/yii2.git
synced 2025-10-29 17:48:15 +08:00
Fix #19855: Fixed yii\validators\FileValidator to not limit some of its rules only to array attribute
This commit is contained in:
@ -29,6 +29,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #20141: Update `ezyang/htmlpurifier` dependency to version `4.17` (@terabytesoftw)
|
||||
- Bug #19817: Add MySQL Query `addCheck()` and `dropCheck()` (@bobonov)
|
||||
- Bug #20165: Adjust pretty name of closures for PHP 8.4 compatibility (@staabm)
|
||||
- Bug #19855: Fixed `yii\validators\FileValidator` to not limit some of its rules only to array attribute (bizley)
|
||||
- Enh: #20171: Support JSON columns for MariaDB 10.4 or higher (@terabytesoftw)
|
||||
|
||||
2.0.49.2 October 12, 2023
|
||||
|
||||
@ -208,40 +208,23 @@ class FileValidator extends Validator
|
||||
*/
|
||||
public function validateAttribute($model, $attribute)
|
||||
{
|
||||
if ($this->maxFiles != 1 || $this->minFiles > 1) {
|
||||
$rawFiles = $model->$attribute;
|
||||
if (!is_array($rawFiles)) {
|
||||
$this->addError($model, $attribute, $this->uploadRequired);
|
||||
$files = $this->filterFiles(is_array($model->$attribute) ? $model->$attribute : [$model->$attribute]);
|
||||
$filesCount = count($files);
|
||||
if ($filesCount === 0 && $this->minFiles > 0) {
|
||||
$this->addError($model, $attribute, $this->uploadRequired);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$files = $this->filterFiles($rawFiles);
|
||||
$model->$attribute = $files;
|
||||
if ($this->maxFiles > 0 && $filesCount > $this->maxFiles) {
|
||||
$this->addError($model, $attribute, $this->tooMany, ['limit' => $this->maxFiles]);
|
||||
}
|
||||
if ($this->minFiles > 0 && $this->minFiles > $filesCount) {
|
||||
$this->addError($model, $attribute, $this->tooFew, ['limit' => $this->minFiles]);
|
||||
}
|
||||
|
||||
if (empty($files)) {
|
||||
$this->addError($model, $attribute, $this->uploadRequired);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$filesCount = count($files);
|
||||
if ($this->maxFiles && $filesCount > $this->maxFiles) {
|
||||
$this->addError($model, $attribute, $this->tooMany, ['limit' => $this->maxFiles]);
|
||||
}
|
||||
|
||||
if ($this->minFiles && $this->minFiles > $filesCount) {
|
||||
$this->addError($model, $attribute, $this->tooFew, ['limit' => $this->minFiles]);
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$result = $this->validateValue($file);
|
||||
if (!empty($result)) {
|
||||
$this->addError($model, $attribute, $result[0], $result[1]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result = $this->validateValue($model->$attribute);
|
||||
foreach ($files as $file) {
|
||||
$result = $this->validateValue($file);
|
||||
if (!empty($result)) {
|
||||
$this->addError($model, $attribute, $result[0], $result[1]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user