parser: return error instead of panic when TZ prefix has no fields#574
Open
nghiack7 wants to merge 2 commits into
Open
parser: return error instead of panic when TZ prefix has no fields#574nghiack7 wants to merge 2 commits into
nghiack7 wants to merge 2 commits into
Conversation
added 2 commits
May 9, 2026 13:47
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
When spec is 'TZ=<zone>' with no trailing schedule fields, Index(' ')
returns -1 and the slice expression spec[eq+1 : -1] panics.
Add an explicit check: if there is no space separator after the timezone
prefix, return a descriptive error immediately.
Fixes robfig#554
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
Fixes #554
ParseStandard("TZ=0")(or anyTZ=/CRON_TZ=prefix without trailing schedule fields) panics with:at
parser.gobecausestrings.Index(spec, " ")returns-1when there is no space, and the slicespec[eq+1 : -1]is invalid.In production systems where cron expressions come from user input, this panic crashes the entire process.
Fix
One-line guard: if
strings.Index(spec, " ")returns-1, return a descriptive error before touching any slice.Tests
Added
TestParseTZMissingFieldsinparser_test.gocovering:"TZ=0"(invalid zone, no fields)"TZ=UTC"(valid zone, no fields)"CRON_TZ=America/New_York"(valid zone, no fields)