Skip to content

Commit

Permalink
tpl/collections: Fix where on type mismatches
Browse files Browse the repository at this point in the history
Fixes #8353
  • Loading branch information
bep committed Apr 23, 2021
1 parent 0d86a32 commit e4dc9a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tpl/collections/where.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
var ima []int64
var fma []float64
var sma []string
if mv.Type() == v.Type() {

if mv.Kind() == v.Kind() {
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
iv := v.Int()
Expand Down
12 changes: 12 additions & 0 deletions tpl/collections/where_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package collections

import (
"fmt"
"html/template"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -146,6 +147,17 @@ func TestWhere(t *testing.T) {
key: "b", match: 2.0, op: ">=",
expect: []map[string]float64{{"a": 1, "b": 2}, {"a": 3, "b": 3}},
},
// Issue #8353
// String type mismatch.
{
seq: []map[string]interface{}{
{"a": "1", "b": "2"}, {"a": "3", "b": template.HTML("4")}, {"a": "5", "x": "4"},
},
key: "b", match: "4",
expect: []map[string]interface{}{
{"a": "3", "b": template.HTML("4")},
},
},
{
seq: []TstX{
{A: "a", B: "b"}, {A: "c", B: "d"}, {A: "e", B: "f"},
Expand Down

0 comments on commit e4dc9a8

Please sign in to comment.