shithub: hugo

Download patch

ref: b60ae35b97c4f44b9b09fcf06c863c695bc3c73a
parent: 003ba5b10f80cdba7151505d9e33b6d96b63a297
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Fri Nov 29 05:50:36 EST 2019

hugolib: Fix timeout number parsing for YAML/JSON config

Where numbers are all floats.

Fixes #6555

--- a/hugolib/image_test.go
+++ b/hugolib/image_test.go
@@ -36,7 +36,7 @@
 	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 @@
 		c.Assert(err, qt.Not(qt.IsNil))
 	}
 
-	b = newBuilder("30s")
+	b = newBuilder(29000)
 	b.Build(BuildCfg{})
 
 	assertImages()
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -413,11 +413,11 @@
 
 	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
 			}