forked from robfig/cron
-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
breaking-changeBreaking API changes for v2Breaking API changes for v2enhancementNew feature or requestNew feature or request
Description
Summary
This change validates that step sizes in cron expressions are meaningful for the given range, preventing silent misbehavior.
Problem
In the original robfig/cron, expressions like */60 in the minute field (range 0-59) were accepted but produced unexpected results:
// Before: Accepted but confusing
_, err := c.AddFunc("*/60 * * * *", myFunc)
// err is nil, but job only runs at minute 0 (not every 60 minutes!)The step of 60 is larger than the range size (60 values: 0-59), making it semantically meaningless.
Solution
Parser now validates that:
- Step size must be positive (> 0)
- Step size must be less than the range size (for steps > 1)
Error message: step (60) must be less than range size (60): */60
Examples of Invalid Expressions
| Expression | Field | Range | Step | Error |
|---|---|---|---|---|
*/60 * * * * |
minute | 0-59 (60 values) | 60 | step >= range size |
*/25 * * * * |
hour field | 0-23 (24 values) | 25 | step >= range size |
*/32 * * * |
day of month | 1-31 (31 values) | 32 | step >= range size |
*/0 * * * * |
any | any | 0 | step must be positive |
Valid Expressions
*/30 * * * *- Every 30 minutes (step 30 < range 60) ✓0 */2 * * *- Every 2 hours (step 2 < range 24) ✓0 0 */7 * *- Every 7 days (step 7 < range 31) ✓
Migration
Users with invalid step expressions will receive a parse error. Review and fix expressions:
*/60 * * * *→0 * * * *(every hour at minute 0)*/90 * * * *→0 */2 * * *(every 2 hours)
Stability Impact
- Severity: Low
- Type: Input validation improvement
- Prevents confusing behavior where jobs don't run as expected
Related
- Part of v0.5.0 release
- Implemented in PR feat: modernize fork with panic fixes, DST handling, and CI #1
- Addresses upstream issue ParseStandard not validating step range robfig/cron#543
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
breaking-changeBreaking API changes for v2Breaking API changes for v2enhancementNew feature or requestNew feature or request