From c127171efbc0e2ebea5a963d89d9a1d9c5ef51a8 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Thu, 24 Oct 2013 02:31:05 +0400 Subject: [PATCH] Fixes #1003: DateValidator returned true for invalid dates --- framework/yii/validators/DateValidator.php | 4 +++- tests/unit/framework/validators/DateValidatorTest.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/yii/validators/DateValidator.php b/framework/yii/validators/DateValidator.php index 2f9e18b..5354b71 100644 --- a/framework/yii/validators/DateValidator.php +++ b/framework/yii/validators/DateValidator.php @@ -70,6 +70,8 @@ class DateValidator extends Validator */ public function validateValue($value) { - return DateTime::createFromFormat($this->format, $value) !== false; + DateTime::createFromFormat($this->format, $value); + $errors = DateTime::getLastErrors(); + return $errors['error_count'] === 0 && $errors['warning_count'] === 0; } } diff --git a/tests/unit/framework/validators/DateValidatorTest.php b/tests/unit/framework/validators/DateValidatorTest.php index 28a6a4a..26c2b46 100644 --- a/tests/unit/framework/validators/DateValidatorTest.php +++ b/tests/unit/framework/validators/DateValidatorTest.php @@ -19,6 +19,7 @@ class DateValidatorTest extends TestCase public function testValidateValue() { $val = new DateValidator; + $this->assertFalse($val->validateValue('3232-32-32')); $this->assertTrue($val->validateValue('2013-09-13')); $this->assertFalse($val->validateValue('31.7.2013')); $this->assertFalse($val->validateValue('31-7-2013'));