Skip to content

Commit 092df97

Browse files
committed
Add check for empty spec
1 parent 9585fd5 commit 092df97

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

parser.go

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func NewParser(options ParseOption) Parser {
7676
// It returns a descriptive error if the spec is not valid.
7777
// It accepts crontab specs and features configured by NewParser.
7878
func (p Parser) Parse(spec string) (Schedule, error) {
79+
if len(spec) == 0 {
80+
return nil, fmt.Errorf("Empty spec string")
81+
}
7982
if spec[0] == '@' && p.options&Descriptor > 0 {
8083
return parseDescriptor(spec)
8184
}

parser_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func TestParse(t *testing.T) {
175175
expr: "* * * *",
176176
err: "Expected 5 to 6 fields",
177177
},
178+
{
179+
expr: "",
180+
err: "Empty spec string",
181+
},
178182
}
179183

180184
for _, c := range entries {

0 commit comments

Comments
 (0)