From b2403f532682394110730c817bdb5497837224b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6rkem=20Taha?= <199121578+Gorkem-Taha@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:22:11 +0300 Subject: [PATCH] Require ASCII digits in cron expressions --- src/validators/cron.py | 6 +++++- tests/test_cron.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/validators/cron.py b/src/validators/cron.py index 7afc4630..028e2362 100644 --- a/src/validators/cron.py +++ b/src/validators/cron.py @@ -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("/") @@ -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. diff --git a/tests/test_cron.py b/tests/test_cron.py index 86723965..88aec34d 100644 --- a/tests/test_cron.py +++ b/tests/test_cron.py @@ -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):