mirror of
https://github.com/danog/liquid.git
synced 2024-11-30 09:48:59 +01:00
Make harmless iterating over value
This commit is contained in:
parent
271f637aae
commit
bad5593bb8
@ -75,6 +75,9 @@ func loopTagParser(node render.BlockNode) (func(io.Writer, render.Context) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
iter := makeIterator(val)
|
iter := makeIterator(val)
|
||||||
|
if iter == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
iter = applyLoopModifiers(loop, iter)
|
iter = applyLoopModifiers(loop, iter)
|
||||||
// shallow-bind the loop variables; restore on exit
|
// shallow-bind the loop variables; restore on exit
|
||||||
defer func(index, forloop interface{}) {
|
defer func(index, forloop interface{}) {
|
||||||
@ -127,6 +130,9 @@ func makeIterator(value interface{}) iterable {
|
|||||||
if iter, ok := value.(iterable); ok {
|
if iter, ok := value.(iterable); ok {
|
||||||
return iter
|
return iter
|
||||||
}
|
}
|
||||||
|
if value == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
switch reflect.TypeOf(value).Kind() {
|
switch reflect.TypeOf(value).Kind() {
|
||||||
case reflect.Array, reflect.Slice:
|
case reflect.Array, reflect.Slice:
|
||||||
return sliceWrapper(reflect.ValueOf(value))
|
return sliceWrapper(reflect.ValueOf(value))
|
||||||
@ -138,7 +144,7 @@ func makeIterator(value interface{}) iterable {
|
|||||||
}
|
}
|
||||||
return sliceWrapper(reflect.ValueOf(array))
|
return sliceWrapper(reflect.ValueOf(array))
|
||||||
default:
|
default:
|
||||||
return sliceWrapper(reflect.ValueOf([]int{}))
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user