Skip to content

Commit 8ea4978

Browse files
committed
Add an explicit ASCII check.
It may seem like this isn't necessary, because: datetime.date.fromisoformat('1963-06-1৪') fails (properly! it's non-ASCII) on CPython, but that's only because the datetime module swaps itself out for the C implementation, and the C implementation blows up on the non-ASCII string. The pure-python implementation (which in some situations may get used) does no check itself for ASCII-ness. There's a comment saying as much here: https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Lib/datetime.py#L266-L267 So, let's check explicitly ourselves regardless of this working occasionally. Thanks PyPy for pointing out the bug.
1 parent f138b23 commit 8ea4978

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

jsonschema/_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def is_regex(instance):
364364
def is_date(instance):
365365
if not isinstance(instance, str):
366366
return True
367-
return _is_date(instance)
367+
return instance.isascii() and datetime.date.fromisoformat(instance)
368368

369369

370370
@_checks_drafts(draft3="time", raises=ValueError)

0 commit comments

Comments
 (0)