diff --git a/parser.go b/parser.go index 8da6547a..80ae2913 100644 --- a/parser.go +++ b/parser.go @@ -95,6 +95,9 @@ func (p Parser) Parse(spec string) (Schedule, error) { if strings.HasPrefix(spec, "TZ=") || strings.HasPrefix(spec, "CRON_TZ=") { var err error i := strings.Index(spec, " ") + if i == -1 { + return nil, fmt.Errorf("provided no location %s", spec) + } eq := strings.Index(spec, "=") 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) diff --git a/parser_test.go b/parser_test.go index 41c8c520..25cd3dc6 100644 --- a/parser_test.go +++ b/parser_test.go @@ -179,6 +179,23 @@ func TestParseSchedule(t *testing.T) { t.Errorf("%s => expected %b, got %b", c.expr, c.expected, actual) } } + + badEntries := []struct { + parser Parser + expr string + }{ + {secondParser, "TZ="}, + {standardParser, "TZ="}, + {secondParser, "CRON_TZ="}, + {standardParser, "CRON_TZ="}, + } + + for _, c := range badEntries { + _, err := c.parser.Parse(c.expr) + if err == nil { + t.Errorf("%s => expected error but got none", c.expr) + } + } } func TestOptionalSecondSchedule(t *testing.T) {