cron icon indicating copy to clipboard operation
cron copied to clipboard

fix: return error instead of panic for TZ= without space

Open Yanhu007 opened this issue 7 months ago • 0 comments

Fixes #554

Problem

cron.ParseStandard("TZ=0") panics with slice bounds out of range because strings.Index(spec, " ") returns -1 when there is no space after the timezone prefix, causing spec[eq+1 : -1] to panic.

This is dangerous in production when user-provided cron expressions are parsed.

Fix

Check if the space index is -1 and return a descriptive error instead of panicking.

Test

_, err := cron.ParseStandard("TZ=0")
// Before: panic: runtime error: slice bounds out of range [3:-1]
// After:  err = "missing time zone specification or fields after TZ="

All existing tests pass.

Yanhu007 avatar Apr 12 '26 23:04 Yanhu007