Skip to content

Commit

Permalink
parser: reject descriptors if not configured to accept them
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Figueiredo committed Feb 12, 2019
1 parent c435534 commit 46e5be3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ func (p Parser) Parse(spec string) (Schedule, error) {
spec = strings.TrimSpace(spec[i:])
}

// Handle named schedules (descriptors)
// Handle named schedules (descriptors), if configured
if strings.HasPrefix(spec, "@") {
if p.options&Descriptor == 0 {
return nil, fmt.Errorf("parser does not accept descriptors: %v", spec)
}
return parseDescriptor(spec, loc)
}

Expand Down
8 changes: 8 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ func TestStandardSpecSchedule(t *testing.T) {
}
}

func TestNoDescriptorParser(t *testing.T) {
parser := NewParser(Minute | Hour)
_, err := parser.Parse("@every 1m")
if err == nil {
t.Error("expected an error, got none")
}
}

func every5min(loc *time.Location) *SpecSchedule {
return &SpecSchedule{1 << 0, 1 << 5, all(hours), all(dom), all(months), all(dow), loc}
}
Expand Down

0 comments on commit 46e5be3

Please sign in to comment.