hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 0816a97a469f11d8e9706143975eaa532e29639b
parent 10a917dfdce8851666c5b89ebc02af6f6c84ab59
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Mon, 12 Feb 2018 18:47:25 +0100

parser: Add WARNING for integer YAML keys

```bash
benchmark                                               old ns/op     new ns/op     delta
BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4     3053          2015          -34.00%
BenchmarkStringifyMapKeysStringsOnlyStringMaps-4        5.23          5.18          -0.96%
BenchmarkStringifyMapKeysIntegers-4                     2320          5177          +123.15%

benchmark                                               old allocs     new allocs     delta
BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4     6              6              +0.00%
BenchmarkStringifyMapKeysStringsOnlyStringMaps-4        0              0              +0.00%
BenchmarkStringifyMapKeysIntegers-4                     6              14             +133.33%

benchmark                                               old bytes     new bytes     delta
BenchmarkStringifyMapKeysStringsOnlyInterfaceMaps-4     1008          1008          +0.00%
BenchmarkStringifyMapKeysStringsOnlyStringMaps-4        0             0             +0.00%
BenchmarkStringifyMapKeysIntegers-4                     1008          1776          +76.19%
```
Closes #4393

Diffstat:
Mparser/frontmatter.go | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/parser/frontmatter.go b/parser/frontmatter.go
@@ -23,6 +23,8 @@ import (
 	"io"
 	"strings"
 
+	"github.com/gohugoio/hugo/helpers"
+
 	"github.com/spf13/cast"
 
 	"github.com/BurntSushi/toml"
@@ -256,10 +258,20 @@ func stringifyMapKeys(in interface{}) (interface{}, bool) {
 		}
 	case map[interface{}]interface{}:
 		res := make(map[string]interface{})
+		var (
+			ok  bool
+			err error
+		)
 		for k, v := range in {
-			ks, err := cast.ToStringE(k)
-			if err != nil {
-				ks = fmt.Sprintf("%v", k)
+			var ks string
+
+			if ks, ok = k.(string); !ok {
+				ks, err = cast.ToStringE(k)
+				if err != nil {
+					ks = fmt.Sprintf("%v", k)
+				}
+				// TODO(bep) added in Hugo 0.37, remove some time in the future.
+				helpers.DistinctFeedbackLog.Printf("WARNING: YAML data/frontmatter with keys of type %T is since Hugo 0.37 converted to strings", k)
 			}
 			if vv, replaced := stringifyMapKeys(v); replaced {
 				res[ks] = vv