Skip to content

Commit 06d8068

Browse files
authoredNov 14, 2020
Merge pull request aptible#78 from krallin/fix-out-of-order-expr
Update cronexpr to reject out-of-order ranges
2 parents 8f8ef8a + 4438829 commit 06d8068

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed
 

‎crontab/crontab.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ func parseJobLine(line string) (*CrontabLine, error) {
3434
scheduleEnds := indices[count-1][1]
3535
commandStarts := indices[count][0]
3636

37+
toParse := line[:scheduleEnds]
38+
3739
// TODO: Should receive a logger?
38-
logrus.Debugf("try parse(%d): %s[0:%d] = %s", count, line, scheduleEnds, line[0:scheduleEnds])
40+
logrus.Debugf("try parse (%d fields): '%s'", count, toParse)
3941

40-
expr, err := cronexpr.ParseStrict(line[:scheduleEnds])
42+
expr, err := cronexpr.ParseStrict(toParse)
4143

4244
if err != nil {
45+
logrus.Debugf("failed to parse (%d fields): '%s': failed: %v", count, toParse, err)
4346
continue
4447
}
4548

@@ -49,7 +52,8 @@ func parseJobLine(line string) (*CrontabLine, error) {
4952
Command: line[commandStarts:],
5053
}, nil
5154
}
52-
return nil, fmt.Errorf("bad crontab line: %s", line)
55+
56+
return nil, fmt.Errorf("bad crontab line: '%s' (use -debug for details)", line)
5357
}
5458

5559
func ParseCrontab(reader io.Reader) (*Crontab, error) {

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/getsentry/raven-go v0.2.0 // indirect
99
github.com/golang/protobuf v1.4.0 // indirect
1010
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
11-
github.com/krallin/cronexpr v0.0.0-20180801141017-b648cc9a908c
11+
github.com/krallin/cronexpr v0.0.0-20201114145102-0373391ef0a2
1212
github.com/pkg/errors v0.9.1 // indirect
1313
github.com/prometheus/client_golang v1.5.1
1414
github.com/prometheus/procfs v0.0.11 // indirect

‎go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
5151
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
5252
github.com/krallin/cronexpr v0.0.0-20180801141017-b648cc9a908c h1:YCO+ApTSaAknMmQAl81m/kwJxbQSbwcx6AX+urZtrg0=
5353
github.com/krallin/cronexpr v0.0.0-20180801141017-b648cc9a908c/go.mod h1:O6noZ1hsovtyM/h0UBv7rU5ps+Y11b+LN9lQ04gWdII=
54+
github.com/krallin/cronexpr v0.0.0-20201114145102-0373391ef0a2 h1:cKXKJnIBL1TmRj7gAcC7fVARLt6JCT97J4+Rjq5DybQ=
55+
github.com/krallin/cronexpr v0.0.0-20201114145102-0373391ef0a2/go.mod h1:3yrSVIYbnN5lC4MIuhQCKpnY02Z0FaHoNJ2E0YYM04g=
5456
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
5557
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
5658
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

0 commit comments

Comments
 (0)
Please sign in to comment.