Просмотр исходного кода

[Validator] fixed error message for dates like 2012-02-31 (closes #4223)

Fabien Potencier 13 лет назад
Родитель
Сommit
facbcdcf45

+ 2 - 2
src/Symfony/Component/Validator/Constraints/DateValidator.php

@@ -48,12 +48,12 @@ class DateValidator extends ConstraintValidator
 
         $value = (string) $value;
 
-        if (!preg_match(static::PATTERN, $value, $matches)) {
+        if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));
 
             return false;
         }
 
-        return checkdate($matches[2], $matches[3], $matches[1]);
+        return true;
     }
 }

+ 1 - 0
tests/Symfony/Tests/Component/Validator/Constraints/DateValidatorTest.php

@@ -73,6 +73,7 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase
     public function testInvalidDates($date)
     {
         $this->assertFalse($this->validator->isValid($date, new Date()));
+        $this->assertEquals('This value is not a valid date', $this->validator->getMessageTemplate());
     }
 
     public function getInvalidDates()