Skip to content

date_parser: out-of-range dates (2024-02-31, 25:61) accepted, TypeError on non-string inputs #402

Closed

Description

@njoubert-cleverage

date_parser accepts invalid dates and fails with a raw error on non-string inputs:

  • Out-of-range dates accepted: \DateTime::createFromFormat() parses an out-of-range value with a warning, the date overflowing, and DateParserTransformer does not check \DateTime::getLastErrors(). 2024-02-31 gives 2024-03-02, 2024-13-01 gives 2025-01-01 and 25:61 is accepted, while the documentation says that a value that cannot be parsed throws an exception.
  • Inputs other than a string: an int (e.g. a timestamp with the U format) or a \Stringable throws a raw TypeError (strict types), and so does an array.

Fix: throw an UnexpectedValueException when \DateTime::getLastErrors() reports warnings; cast the scalars and \Stringable to string, explicit UnexpectedValueException for the other values.

Found during the audit v3 (audit-v3-angles.md #195, and #202 for date_parser).

Activity

  1. added a commit that references this issue on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions