diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-23 11:05:15 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-23 18:06:49 +0200 |
commit | e4dc9a82b557a417b1552c533b0df605c6ff1cc0 (patch) | |
tree | 1f1d49746dc10ff655620932dfb6f701240bdc45 | |
parent | 0d86a32d8f3031e2124c8005b680b597f3c0e558 (diff) |
tpl/collections: Fix where on type mismatches
Fixes #8353
-rw-r--r-- | tpl/collections/where.go | 3 | ||||
-rw-r--r-- | tpl/collections/where_test.go | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/tpl/collections/where.go b/tpl/collections/where.go index c371f6ae8..8ffcf6165 100644 --- a/tpl/collections/where.go +++ b/tpl/collections/where.go @@ -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() diff --git a/tpl/collections/where_test.go b/tpl/collections/where_test.go index 47b61bdca..2a97c8cd0 100644 --- a/tpl/collections/where_test.go +++ b/tpl/collections/where_test.go @@ -15,6 +15,7 @@ package collections import ( "fmt" + "html/template" "reflect" "strings" "testing" @@ -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"}, |