Merge branch 'master' of github.com:gorhill/cronexpr

This commit is contained in:
Chris Jarabek 2018-03-19 15:32:04 -06:00
commit d4924d506e
2 changed files with 32 additions and 0 deletions

View File

@ -450,6 +450,9 @@ func genericFieldParse(s string, desc fieldDescriptor) ([]*cronDirective, error)
directive.first = desc.min
directive.last = desc.max
directive.step = atoi(snormal[pairs[2]:pairs[3]])
if directive.step < 1 || directive.step > desc.max {
return nil, fmt.Errorf("invalid interval %s", snormal)
}
directives = append(directives, &directive)
continue
}
@ -460,6 +463,9 @@ func genericFieldParse(s string, desc fieldDescriptor) ([]*cronDirective, error)
directive.first = desc.atoi(snormal[pairs[2]:pairs[3]])
directive.last = desc.max
directive.step = atoi(snormal[pairs[4]:pairs[5]])
if directive.step < 1 || directive.step > desc.max {
return nil, fmt.Errorf("invalid interval %s", snormal)
}
directives = append(directives, &directive)
continue
}
@ -470,6 +476,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 = atoi(snormal[pairs[6]:pairs[7]])
if directive.step < 1 || directive.step > desc.max {
return nil, fmt.Errorf("invalid interval %s", snormal)
}
directives = append(directives, &directive)
continue
}

View File

@ -293,6 +293,29 @@ func TestNextN_every5min(t *testing.T) {
}
}
// Issue: https://github.com/gorhill/cronexpr/issues/16
func TestInterval_Interval60Issue(t *testing.T){
_, err := cronexpr.Parse("*/60 * * * * *")
if err == nil {
t.Errorf("parsing with interval 60 should return err")
}
_, err = cronexpr.Parse("*/61 * * * * *")
if err == nil {
t.Errorf("parsing with interval 61 should return err")
}
_, err = cronexpr.Parse("2/60 * * * * *")
if err == nil {
t.Errorf("parsing with interval 60 should return err")
}
_, err = cronexpr.Parse("2-20/61 * * * * *")
if err == nil {
t.Errorf("parsing with interval 60 should return err")
}
}
/******************************************************************************/
var benchmarkExpressions = []string{