summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxiaofan <wangxiaofan@xiaomi.com>2016-12-05 11:16:12 +0800
committerxiaofan <wangxiaofan@xiaomi.com>2016-12-05 11:16:12 +0800
commit86090e60c22fdb98fb7e0c80afd94deb09ac6299 (patch)
tree9a4e3333f4b57c396528bd98d3c96b5609f5cee4
parentf0984319b44273e83de132089ae42b1810f4933b (diff)
downloadcronexpr-86090e60c22fdb98fb7e0c80afd94deb09ac6299.tar.xz
fix 60 interval issue
-rw-r--r--cronexpr_parse.go9
-rw-r--r--cronexpr_test.go23
2 files changed, 32 insertions, 0 deletions
diff --git a/cronexpr_parse.go b/cronexpr_parse.go
index aeb8296..be6ef17 100644
--- a/cronexpr_parse.go
+++ b/cronexpr_parse.go
@@ -446,6 +446,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
}
@@ -456,6 +459,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
}
@@ -466,6 +472,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
}
diff --git a/cronexpr_test.go b/cronexpr_test.go
index b729170..f170769 100644
--- a/cronexpr_test.go
+++ b/cronexpr_test.go
@@ -284,6 +284,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{