mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-20 02:53:12 +00:00
parent
ddd8c77938
commit
4c04d7101a
2 changed files with 9 additions and 0 deletions
|
@ -330,6 +330,10 @@ func In(l interface{}, v interface{}) bool {
|
||||||
case reflect.Array, reflect.Slice:
|
case reflect.Array, reflect.Slice:
|
||||||
for i := 0; i < lv.Len(); i++ {
|
for i := 0; i < lv.Len(); i++ {
|
||||||
lvv := lv.Index(i)
|
lvv := lv.Index(i)
|
||||||
|
lvv, isNil := indirect(lvv)
|
||||||
|
if isNil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
switch lvv.Kind() {
|
switch lvv.Kind() {
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
if vv.Type() == lvv.Type() && vv.String() == lvv.String() {
|
if vv.Type() == lvv.Type() && vv.String() == lvv.String() {
|
||||||
|
|
|
@ -354,9 +354,14 @@ func TestIn(t *testing.T) {
|
||||||
expect bool
|
expect bool
|
||||||
}{
|
}{
|
||||||
{[]string{"a", "b", "c"}, "b", true},
|
{[]string{"a", "b", "c"}, "b", true},
|
||||||
|
{[]interface{}{"a", "b", "c"}, "b", true},
|
||||||
|
{[]interface{}{"a", "b", "c"}, "d", false},
|
||||||
{[]string{"a", "b", "c"}, "d", false},
|
{[]string{"a", "b", "c"}, "d", false},
|
||||||
{[]string{"a", "12", "c"}, 12, false},
|
{[]string{"a", "12", "c"}, 12, false},
|
||||||
{[]int{1, 2, 4}, 2, true},
|
{[]int{1, 2, 4}, 2, true},
|
||||||
|
{[]interface{}{1, 2, 4}, 2, true},
|
||||||
|
{[]interface{}{1, 2, 4}, nil, false},
|
||||||
|
{[]interface{}{nil}, nil, false},
|
||||||
{[]int{1, 2, 4}, 3, false},
|
{[]int{1, 2, 4}, 3, false},
|
||||||
{[]float64{1.23, 2.45, 4.67}, 1.23, true},
|
{[]float64{1.23, 2.45, 4.67}, 1.23, true},
|
||||||
{[]float64{1.234567, 2.45, 4.67}, 1.234568, false},
|
{[]float64{1.234567, 2.45, 4.67}, 1.234568, false},
|
||||||
|
|
Loading…
Add table
Reference in a new issue