diff --git a/cronexpr_parse.go b/cronexpr_parse.go index a9fe746..27683c6 100644 --- a/cronexpr_parse.go +++ b/cronexpr_parse.go @@ -438,6 +438,9 @@ func genericFieldParse(s string, desc fieldDescriptor) ([]*cronDirective, error) directive.first = desc.atoi(snormal[pairs[2]:pairs[3]]) directive.last = desc.atoi(snormal[pairs[4]:pairs[5]]) directive.step = 1 + if directive.last < directive.first { + return nil, fmt.Errorf("invalid interval %s (normalized to %d-%d)", snormal, directive.first, directive.last) + } directives = append(directives, &directive) continue } diff --git a/cronexpr_test.go b/cronexpr_test.go index 0af28c4..8bf8d4d 100644 --- a/cronexpr_test.go +++ b/cronexpr_test.go @@ -305,6 +305,19 @@ func TestInterval_Interval60Issue(t *testing.T) { } } +// Issue: https://github.com/aptible/supercronic/issues/63 +func TestRange_OutOfOrder(t *testing.T) { + _, err := Parse("45 4 * * 6-7") + if err == nil { + t.Errorf("parsing with range 6-7 should return err") + } + + _, err = Parse("45 4 * * 6-5") + if err == nil { + t.Errorf("parsing with range 6-5 should return err") + } +} + /******************************************************************************/ func TestTooManyFields(t *testing.T) {