diff options
author | Vazrupe (HyeonGyu Lee) <[email protected]> | 2019-10-09 18:36:25 +0900 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-10-11 10:38:12 +0200 |
commit | a9762b5c48054e036332eff541a8fd32e54ada13 (patch) | |
tree | 6f133ff57ebb7109c42db7b4ab0afcef21f178e9 /common/collections | |
parent | 096a4b67b98259dabff5ebfbfd879a41999a1ed2 (diff) | |
download | hugo-a9762b5c48054e036332eff541a8fd32e54ada13.tar.gz hugo-a9762b5c48054e036332eff541a8fd32e54ada13.zip |
common: Fix elements are doubling when append a not assignable type
Fixes #6188
Diffstat (limited to 'common/collections')
-rw-r--r-- | common/collections/append.go | 1 | ||||
-rw-r--r-- | common/collections/append_test.go | 2 |
2 files changed, 3 insertions, 0 deletions
diff --git a/common/collections/append.go b/common/collections/append.go index ee15fef7d..b56455bc9 100644 --- a/common/collections/append.go +++ b/common/collections/append.go @@ -65,6 +65,7 @@ func Append(to interface{}, from ...interface{}) (interface{}, error) { fv := reflect.ValueOf(f) if !fv.Type().AssignableTo(tot) { // Fall back to a []interface{} slice. + tov, _ := indirect(reflect.ValueOf(to)) return appendToInterfaceSlice(tov, from...) } tov = reflect.Append(tov, fv) diff --git a/common/collections/append_test.go b/common/collections/append_test.go index 8c9a6e73f..4086570b8 100644 --- a/common/collections/append_test.go +++ b/common/collections/append_test.go @@ -14,6 +14,7 @@ package collections import ( + "html/template" "testing" qt "github.com/frankban/quicktest" @@ -31,6 +32,7 @@ func TestAppend(t *testing.T) { {[]string{"a", "b"}, []interface{}{"c"}, []string{"a", "b", "c"}}, {[]string{"a", "b"}, []interface{}{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}}, {[]string{"a", "b"}, []interface{}{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}}, + {[]string{"a"}, []interface{}{"b", template.HTML("c")}, []interface{}{"a", "b", template.HTML("c")}}, {nil, []interface{}{"a", "b"}, []string{"a", "b"}}, {nil, []interface{}{nil}, []interface{}{nil}}, {[]interface{}{}, []interface{}{[]string{"c", "d", "e"}}, []string{"c", "d", "e"}}, |