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
19 changes: 10 additions & 9 deletions src/validators/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ def _validate_cron_component(component: str, min_val: int, max_val: int):
if component == "*":
return True

# A comma-separated list must be split first, so each element can itself be
# a range (e.g. "1-5"), a step (e.g. "*/2") or a single value. Evaluating
# the "-" or "/" branches before this one caused valid expressions such as
# "1-5,10-20" to be rejected.
if "," in component:
for item in component.split(","):
if not _validate_cron_component(item, min_val, max_val):
return False
return True

if component.isdecimal():
return min_val <= int(component) <= max_val

Expand All @@ -26,15 +36,6 @@ def _validate_cron_component(component: str, min_val: int, max_val: int):
start, end = int(parts[0]), int(parts[1])
return min_val <= start <= max_val and min_val <= end <= max_val and start <= end

if "," in component:
for item in component.split(","):
if not _validate_cron_component(item, min_val, max_val):
return False
return True
# return all(
# _validate_cron_component(item, min_val, max_val) for item in component.split(",")
# ) # throws type error. why?

return False


Expand Down
4 changes: 4 additions & 0 deletions tests/test_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"*/15 0,6,12,18 * * *",
"0 12 * * 0",
"*/61 * * * *",
"1-5,10-20 * * * *",
"1-5,30 * * * *",
"10,20-30 * * * *",
"1-5,10-20,30-40 * * * *",
# "5-10/2 * * * *", # this is valid, but not supported yet
],
)
Expand Down