diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index bad043f20e..8d0350532d 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -57,6 +57,12 @@ class DateTimeValidator extends DateValidator return; } + if('+' === substr($constraint->format, -1)) { + $errors['warnings'] = array_filter($errors['warnings'], function($warning) { + return 'Trailing data' !== $warning; + }); + } + foreach ($errors['warnings'] as $warning) { if ('The parsed date was invalid' === $warning) { $this->context->buildViolation($constraint->message) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 55bfe45143..8ff515772d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -128,4 +128,12 @@ class DateTimeValidatorTest extends ConstraintValidatorTestCase ['Y-m-d H:i:s', '2010-01-01 00:00:60', DateTime::INVALID_TIME_ERROR], ]; } + + public function testDateTimeWithTrailingData() + { + $this->validator->validate('1995-05-10 00:00:00', new DateTime([ + 'format' => 'Y-m-d+', + ])); + $this->assertNoViolation(); + } }