From b60ae35b97c4f44b9b09fcf06c863c695bc3c73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 29 Nov 2019 10:50:36 +0100 Subject: [PATCH] hugolib: Fix timeout number parsing for YAML/JSON config Where numbers are all floats. Fixes #6555 --- hugolib/image_test.go | 4 ++-- hugolib/site.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hugolib/image_test.go b/hugolib/image_test.go index 315da6b78..cd7ec7a7e 100644 --- a/hugolib/image_test.go +++ b/hugolib/image_test.go @@ -36,7 +36,7 @@ func TestImageOps(t *testing.T) { c.Assert(err, qt.IsNil) defer clean() - newBuilder := func(timeout string) *sitesBuilder { + newBuilder := func(timeout interface{}) *sitesBuilder { v := viper.New() v.Set("workingDir", workDir) @@ -152,7 +152,7 @@ IMG SHORTCODE: /images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_129x239_r c.Assert(err, qt.Not(qt.IsNil)) } - b = newBuilder("30s") + b = newBuilder(29000) b.Build(BuildCfg{}) assertImages() diff --git a/hugolib/site.go b/hugolib/site.go index 69e745e61..1df7d6076 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -413,11 +413,11 @@ func newSite(cfg deps.DepsCfg) (*Site, error) { timeout := 30 * time.Second if cfg.Language.IsSet("timeout") { - switch v := cfg.Language.Get("timeout").(type) { - case int64: - timeout = time.Duration(v) * time.Millisecond - case string: - d, err := time.ParseDuration(v) + v := cfg.Language.Get("timeout") + if n := cast.ToInt(v); n > 0 { + timeout = time.Duration(n) * time.Millisecond + } else { + d, err := time.ParseDuration(cast.ToString(v)) if err == nil { timeout = d }