Skip to content

Commit

Permalink
check for empty interval string
Browse files Browse the repository at this point in the history
  • Loading branch information
deniszh committed Jan 18, 2024
1 parent 4030828 commit bf13902
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/parser/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import (

// IntervalString converts a sign and string into a number of seconds
func IntervalString(s string, defaultSign int) (int32, error) {
if len(s) == 0 {
return 0, ErrUnknownTimeUnits
}

if s == "-" || s == "+" {
return 0, ErrUnknownTimeUnits
}

sign := defaultSign

Expand Down
3 changes: 3 additions & 0 deletions pkg/parser/interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func TestInterval(t *testing.T) {
err string
sign int
}{
{"", 0, "unknown time units", 1},
{"-", 0, "unknown time units", 1},
{"+", 0, "unknown time units", 1},
{"10x10s", 0, "unknown time units", 1},
{"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000y", 0, "value out of range", 1},
}
Expand Down

0 comments on commit bf13902

Please sign in to comment.