fix: validate that step does not exceed field range#573
Open
nghiack7 wants to merge 12 commits into
Open
Conversation
remove redundant asterisk in example
docs: remove redundant asterisk in example
Let cron depend on interface for parsers instead of fixed parser
Fix changing quartz scheduler site link for README
It was an error in channel scoping that was identified in pull robfig#263. This adds a unit test to identify that issue and verify the fix.
A step value larger than the field's own range (e.g. */90 in minutes
where max=59) would silently accept the expression and schedule the job
only at the range minimum, hiding a likely user error.
Add a validation check after the step is parsed:
if step > r.max-r.min {
return 0, fmt.Errorf("step (%d) above maximum (%d): ...", ...)
}
This mirrors the existing checks for start/end bounds and returns a
clear error rather than silently mis-scheduling.
Add two test cases to TestStandardSpecSchedule exercising the new
validation for the minute and hour fields.
Fixes robfig#543
Author
|
Friendly ping — this PR is ready for review. CI is clean ✅. Happy to make any changes requested. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ParseStandard("*/90 * * * *")silently accepts an invalid expression and schedules the job at minute 0 only (every hour), instead of returning an error.A step value larger than the field's own range — e.g.
90in the minutes field (range0-59) — can never produce more than one trigger point. This hides a clear user mistake and leads to unexpected scheduling behaviour.Reported in issue #543.
Root cause
getRangevalidates thatstart >= r.min,end <= r.max,start <= end, andstep > 0, but never checks thatstepitself is within the field's range.Fix
One additional check after the step is parsed:
This mirrors the style of the existing bounds checks and returns a clear, descriptive error.
Tests
Added two error-path cases to
TestStandardSpecSchedule:*/90 * * * ** */30 * * *All existing tests continue to pass.