From 225cb3b6c7cfe19d7fb49846e6915e24eee13bae Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Mon, 13 Apr 2026 07:06:57 +0800 Subject: [PATCH] fix: return error instead of panic for TZ= without space ParseStandard("TZ=0") panics because strings.Index(spec, " ") returns -1 when there is no space after the timezone, causing spec[eq+1 : -1] to panic with a slice bounds out of range error. Check for i == -1 and return a descriptive error instead. Fixes #554 --- parser.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parser.go b/parser.go index 8da6547a..21b590ba 100644 --- a/parser.go +++ b/parser.go @@ -96,6 +96,9 @@ func (p Parser) Parse(spec string) (Schedule, error) { var err error i := strings.Index(spec, " ") eq := strings.Index(spec, "=") + if i == -1 { + return nil, fmt.Errorf("missing time zone specification or fields after %s", spec[:eq+1]) + } if loc, err = time.LoadLocation(spec[eq+1 : i]); err != nil { return nil, fmt.Errorf("provided bad location %s: %v", spec[eq+1:i], err) }