From 662db7a944a44d7b594375b7071c8dfc12618a7d Mon Sep 17 00:00:00 2001 From: Alex Zorin Date: Tue, 25 Oct 2016 18:30:01 +1100 Subject: [PATCH] Fix panic in internal.Duration UnmarshalTOML --- internal/internal.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/internal.go b/internal/internal.go index 664a1d13b..a278d2da0 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -35,10 +35,13 @@ type Duration struct { // UnmarshalTOML parses the duration from the TOML config file func (d *Duration) UnmarshalTOML(b []byte) error { var err error + // Parse string duration, ie, "1s" - d.Duration, err = time.ParseDuration(string(b[1 : len(b)-1])) - if err == nil { - return nil + if uq, err := strconv.Unquote(string(b)); err == nil && len(uq) > 0 { + d.Duration, err = time.ParseDuration(uq) + if err == nil { + return nil + } } // First try parsing as integer seconds