Permalink
Browse files

common/collections: Fix type checking in Append

The fix introduced in Hugo `0.49.1` had an unintended side-effect in the `Append` func used in both `append` and `.Scratch.Add`.

This commit fixes that by loosen/fixing the type checking so concrete types can be appended to interface slices.

Fixes #5303
  • Loading branch information...
bep committed Oct 11, 2018
1 parent 821adf3 commit 2159d77f368eb1f78e51dd94133554f88052d85f
Showing with 7 additions and 1 deletion.
  1. +1 −1 common/collections/append.go
  2. +6 −0 common/collections/append_test.go
@@ -59,7 +59,7 @@ func Append(to interface{}, from ...interface{}) (interface{}, error) {
for _, f := range from {
fv := reflect.ValueOf(f)
if tot != fv.Type() {
if !fv.Type().AssignableTo(tot) {
return nil, fmt.Errorf("append element type mismatch: expected %v, got %v", tot, fv.Type())
}
tov = reflect.Append(tov, fv)
@@ -43,7 +43,13 @@ func TestAppend(t *testing.T) {
tstSlicers{&tstSlicer{"a"},
&tstSlicer{"b"},
&tstSlicer{"c"}}},
{testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}},
[]interface{}{&tstSlicerIn1{"c"}},
testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}, &tstSlicerIn1{"c"}}},
// Errors
{testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}},
[]interface{}{"c"},
false},
{"", []interface{}{[]string{"a", "b"}}, false},
// No string concatenation.
{"ab",

0 comments on commit 2159d77

Please sign in to comment.