Skip to content

Commit

Permalink
common: Fix elements are doubling when append a not assignable type
Browse files Browse the repository at this point in the history
Fixes #6188
  • Loading branch information
vazrupe authored and bep committed Oct 11, 2019
1 parent 096a4b6 commit a9762b5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/collections/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions common/collections/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package collections

import (
"html/template"
"testing"

qt "github.com/frankban/quicktest"
Expand All @@ -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"}},
Expand Down

0 comments on commit a9762b5

Please sign in to comment.