Skip to content

Commit

Permalink
Merge pull request #1076 from jvtm/python311-date-fromisoformat-allow…
Browse files Browse the repository at this point in the history
…s-extra-formats

fix: Python 3.11 date.fromisoformat() allows extra formats
  • Loading branch information
Julian committed Mar 28, 2023
2 parents d09feb6 + 781f8cd commit 8b8f355
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion jsonschema/_format.py
Expand Up @@ -17,6 +17,8 @@
typing.Type[Exception], typing.Tuple[typing.Type[Exception], ...],
]

_RE_DATE = re.compile(r"^\d{4}-\d{2}-\d{2}$", re.ASCII)


class FormatChecker:
"""
Expand Down Expand Up @@ -396,7 +398,10 @@ def is_regex(instance: object) -> bool:
def is_date(instance: object) -> bool:
if not isinstance(instance, str):
return True
return bool(instance.isascii() and datetime.date.fromisoformat(instance))
return bool(
_RE_DATE.fullmatch(instance)
and datetime.date.fromisoformat(instance)
)


@_checks_drafts(draft3="time", raises=ValueError)
Expand Down

0 comments on commit 8b8f355

Please sign in to comment.