| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The comma-list branch in _validate_cron_component was evaluated after the '-' and '/' branches, so any list element that was itself a range (e.g. '1-5') or step (e.g. '*/2') short-circuited and the whole expression was rejected. Move the comma-list split to run first, so each element is validated as a range/step/single value. Adds regression cases for list-of-ranges, list-with-single, and multi-list expressions.
|
Gentle nudge on this one. The cron-list-of-ranges fix is bite-tested (the added test fails on current master and passes with the change), and the branch is clean against master. Happy to rework if you'd prefer a different approach. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
cron() rejects valid expressions whose components are comma-separated lists of ranges or steps, e.g. cron("1-5,10-20 * * * *") raises ValidationError even though the expression is valid.
Reproduction
Validity currently depends on element order, which is the clearest sign this is a bug rather than an intended limitation:
Cause
In src/validators/cron.py, _validate_cron_component checks the "-" and "/" branches before the "," branch. A component like "1-5,10-20" therefore matches the range branch, split("-") yields three parts, and the whole expression is rejected.
Fix
Evaluate the "," branch first, recursing on each element so each element can itself be a single value, a range ("1-5"), or a step ("*/2").
if component == "*": return True + 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():No previously-accepted input changes behaviour: any component containing a comma previously hit the range branch and was rejected, so this only accepts inputs that were wrongly rejected. The existing dead commented all(...) block is removed.
Tests
Adds four cases to test_returns_true_on_valid_cron:
Each fails on the current code and passes with the fix. Full suite: 895 → 899 passing. ruff check / ruff format clean.
I couldn't find an existing issue or PR covering this — happy to fold it into one if I missed it.