FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(cron): validate comma-separated lists of ranges and steps by patchwright · Pull Request #463 · python-validators/validators · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
19 changes: 10 additions & 9 deletions src/validators/cron.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL