Skip to content

Commit

Permalink
model.Duration: disallow empty string
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
  • Loading branch information
roidelapluie committed Aug 3, 2020
1 parent 9c5aa1e commit 3b24f1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions model/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func ParseDuration(durationStr string) (Duration, error) {
if durationStr == "0" {
return 0, nil
}
if durationStr == "" {
return 0, fmt.Errorf("empty duration string")
}
matches := durationRE.FindStringSubmatch(durationStr)
if matches == nil {
return 0, fmt.Errorf("not a valid duration string: %q", durationStr)
Expand Down
1 change: 1 addition & 0 deletions model/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func TestParseBadDuration(t *testing.T) {
"1y1m1d",
"-1w",
"1.5d",
"",
}

for _, c := range cases {
Expand Down

0 comments on commit 3b24f1e

Please sign in to comment.