Skip to content

datetime.fromisoformat() accepts invalid ISO 8601 timestamps #115783

Open
@Paebbels

Description

@Paebbels

Bug report

Bug description:

Since Python 3.11, datetime.fromisoformat(...) accepts invalid timestamps. The same code was tested in many Python versions via GitHub Actions:

Wrong format: 2024-01-17T15:21:00-0800
Fixed format: 2024-01-17T15:21:00-08:00

Python code to check:

datetime.fromisoformat("2024-01-17T15:21:00-0800")

ISO 8601 defines 2 formats:

  • basic format (in short: without separators) and
  • extended format (with separators).

When checking the EBNF rules, all parts of the timestamp must be with or without separators. A mix of formats is not allowed.

I haven't checked for other basic and extended format mixes.
My CI checked many Python versions and platforms. Here a failed CI pipeline, shows a correct implementation. A successful pipeline denotes a buggy Python version.
image

Other resources:

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13

Operating systems tested on:

Linux, macOS, Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions