Browse Source

Fixes #1003: DateValidator returned true for invalid dates

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
c127171efb
  1. 4
      framework/yii/validators/DateValidator.php
  2. 1
      tests/unit/framework/validators/DateValidatorTest.php

4
framework/yii/validators/DateValidator.php

@ -70,6 +70,8 @@ class DateValidator extends Validator
*/ */
public function validateValue($value) 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;
} }
} }

1
tests/unit/framework/validators/DateValidatorTest.php

@ -19,6 +19,7 @@ class DateValidatorTest extends TestCase
public function testValidateValue() public function testValidateValue()
{ {
$val = new DateValidator; $val = new DateValidator;
$this->assertFalse($val->validateValue('3232-32-32'));
$this->assertTrue($val->validateValue('2013-09-13')); $this->assertTrue($val->validateValue('2013-09-13'));
$this->assertFalse($val->validateValue('31.7.2013')); $this->assertFalse($val->validateValue('31.7.2013'));
$this->assertFalse($val->validateValue('31-7-2013')); $this->assertFalse($val->validateValue('31-7-2013'));

Loading…
Cancel
Save