Skip to content

Date validation accepts invalid dates #14727

Closed
@peter17

Description

@peter17

In Symfony-2.6.7, I am using a form with type date, 'format' => 'yyyy-MM-dd' and constraint => array(new Symfony\Component\Validator\Constraints\Date).

When a user inputs a date with a five-digit year, the form is validated successfully but an incorrect date is persisted.

Example:
User inputs 20011-11-11. Persisted date is 2001-11-11.

It is probably not Symfony's fault, since PHP's DateTime('20011-11-11') indeed returns object(DateTime)#1 (3) { ["date"]=> string(26) "2001-11-11 20:01:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }. See http://3v4l.org/tCrGl for version details.

20011-11-11 should either be accepted as valid or rejected as invalid but not transformed to something else and accepted... Could Symfony validate the string format before PHP transforms it to a date?

Best regards

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions