From 807223efbf7c009d54378d9c451d79872dca14a2 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 31 Jan 2014 21:48:46 -0500 Subject: [PATCH] Fixes #1412 --- framework/CHANGELOG.md | 2 +- framework/validators/FileValidator.php | 2 +- framework/validators/ImageValidator.php | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 79921db..4df30c5 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -6,7 +6,7 @@ Yii Framework 2 Change Log - Bug #1265: AssetController does not override 'js' and 'css' for compressed bundles (klimov-paul) - Bug #1326: The `visible` setting for `DetailView` doesn't work as expected (qiangxue) -- Bug #1412: `FileValidator` still triggers `uploadRequired` error in some case when `skipOnEmpty` is true and no upload is provided (qiangxue) +- Bug #1412: `FileValidator` and `ImageValidator` still trigger `uploadRequired` error in some case when `skipOnEmpty` is true and no upload is provided (qiangxue) - Bug #1446: Logging while logs are processed causes infinite loop (qiangxue) - Bug #1497: Localized view files are not correctly returned (mintao) - Bug #1500: Log messages exported to files are not separated by newlines (omnilight, qiangxue) diff --git a/framework/validators/FileValidator.php b/framework/validators/FileValidator.php index ae1ef89..b09cfa5 100644 --- a/framework/validators/FileValidator.php +++ b/framework/validators/FileValidator.php @@ -167,7 +167,7 @@ class FileValidator extends Validator protected function validateValue($file) { if (!$file instanceof UploadedFile || $file->error == UPLOAD_ERR_NO_FILE) { - return $this->skipOnEmpty ? [] : [$this->uploadRequired, []]; + return $this->skipOnEmpty ? null : [$this->uploadRequired, []]; } switch ($file->error) { case UPLOAD_ERR_OK: diff --git a/framework/validators/ImageValidator.php b/framework/validators/ImageValidator.php index 52fb235..4bdbc23 100644 --- a/framework/validators/ImageValidator.php +++ b/framework/validators/ImageValidator.php @@ -144,8 +144,12 @@ class ImageValidator extends FileValidator */ protected function validateValue($file) { - $result = parent::validateValue($file); - return empty($result) ? $this->validateImage($file) : $result; + if ($this->skipOnEmpty && (!$file instanceof UploadedFile || $file->error == UPLOAD_ERR_NO_FILE)) { + return null; + } else { + $result = parent::validateValue($file); + return empty($result) ? $this->validateImage($file) : $result; + } } /**