Browse Source

Merge pull request #88 from soltysh/empty_spec

Add check for empty spec
Rob Figueiredo 8 years ago
parent
commit
d9e2c86624
2 changed files with 7 additions and 0 deletions
  1. 3 0
      parser.go
  2. 4 0
      parser_test.go

+ 3 - 0
parser.go

@@ -76,6 +76,9 @@ func NewParser(options ParseOption) Parser {
 // It returns a descriptive error if the spec is not valid.
 // It accepts crontab specs and features configured by NewParser.
 func (p Parser) Parse(spec string) (Schedule, error) {
+	if len(spec) == 0 {
+		return nil, fmt.Errorf("Empty spec string")
+	}
 	if spec[0] == '@' && p.options&Descriptor > 0 {
 		return parseDescriptor(spec)
 	}

+ 4 - 0
parser_test.go

@@ -175,6 +175,10 @@ func TestParse(t *testing.T) {
 			expr: "* * * *",
 			err:  "Expected 5 to 6 fields",
 		},
+		{
+			expr: "",
+			err:  "Empty spec string",
+		},
 	}
 
 	for _, c := range entries {