Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-11 12:05:30 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-11 12:24:10 +0300
commit535755e4f80d96b42a9be05fa85c7827a5e1dbc7 (patch)
tree57f54bbe7b591a7805697f5d14e9bfbbe3e2c627 /common
parent3583dd6d713c243808b5e8724b32565ceaf66104 (diff)
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
Diffstat (limited to 'common')
-rw-r--r--common/collections/append.go2
-rw-r--r--common/collections/append_test.go6
2 files changed, 7 insertions, 1 deletions
diff --git a/common/collections/append.go b/common/collections/append.go
index e1008843b..97bf84988 100644
--- a/common/collections/append.go
+++ b/common/collections/append.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)
diff --git a/common/collections/append_test.go b/common/collections/append_test.go
index e3361fb26..f89ec60f0 100644
--- a/common/collections/append_test.go
+++ b/common/collections/append_test.go
@@ -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",