common: Fix elements are doubling when append a not assignable type
authorVazrupe (HyeonGyu Lee) <vazrupe@naver.com>
Wed, 9 Oct 2019 09:36:25 +0000 (18:36 +0900)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 11 Oct 2019 08:38:12 +0000 (10:38 +0200)
Fixes #6188

common/collections/append.go
common/collections/append_test.go

index ee15fef7da69cca76bc1f65c8cfdb499d72976dd..b56455bc900c7f3518e24620f6aaebe368b75d5d 100644 (file)
@@ -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)
index 8c9a6e73f3319718a6c776c5310d4e453897f843..4086570b85ba08ba51511f77c28c8abf91d28ae7 100644 (file)
@@ -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"}},