Fix panic in internal.Duration UnmarshalTOML

This commit is contained in:
Alex Zorin 2016-10-25 18:30:01 +11:00
parent c849b58de9
commit 662db7a944
1 changed files with 6 additions and 3 deletions

View File

@ -35,11 +35,14 @@ type Duration struct {
// UnmarshalTOML parses the duration from the TOML config file // UnmarshalTOML parses the duration from the TOML config file
func (d *Duration) UnmarshalTOML(b []byte) error { func (d *Duration) UnmarshalTOML(b []byte) error {
var err error var err error
// Parse string duration, ie, "1s" // Parse string duration, ie, "1s"
d.Duration, err = time.ParseDuration(string(b[1 : len(b)-1])) if uq, err := strconv.Unquote(string(b)); err == nil && len(uq) > 0 {
d.Duration, err = time.ParseDuration(uq)
if err == nil { if err == nil {
return nil return nil
} }
}
// First try parsing as integer seconds // First try parsing as integer seconds
sI, err := strconv.ParseInt(string(b), 10, 64) sI, err := strconv.ParseInt(string(b), 10, 64)