Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/validators/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@


def _validate_cron_item(item: str, min_val: int, max_val: int):
# str.isdecimal() and int() also accept digits outside cron's ASCII syntax.
if not item.isascii():
return False

# An item may carry a step, e.g. "*/5", "1-30/2" or "5/10".
if "/" in item:
base, _, step = item.partition("/")
Expand Down Expand Up @@ -46,7 +50,7 @@ def cron(value: str, /):

Args:
value:
Cron string to validate.
Cron string to validate. Numeric fields use ASCII digits.

Returns:
(Literal[True]): If `value` is a valid cron string.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ def test_returns_true_on_valid_cron(value: str):
"*/15 0,6,12,24 * * *",
"& * * & * *",
"* - * * - *",
"٣٠ 3 * * *",
"30 3 * * *",
"३० 3 * * *",
"0 ٣ * * *",
"0 0 ١ * *",
"0 0 * ١ *",
"0 0 * * ١",
"١-5 * * * *",
"1-٥ * * * *",
"1,٣ * * * *",
"*/٢ * * * *",
"1-5/٢ * * * *",
"١/2 * * * *",
],
)
def test_returns_failed_validation_on_invalid_cron(value: str):
Expand Down