1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 01:34:41 +01:00

Make harmless iterating over value

This commit is contained in:
Oliver Steele 2017-07-13 18:59:10 -04:00
parent 271f637aae
commit bad5593bb8

View File

@ -75,6 +75,9 @@ func loopTagParser(node render.BlockNode) (func(io.Writer, render.Context) error
return err
}
iter := makeIterator(val)
if iter == nil {
return nil
}
iter = applyLoopModifiers(loop, iter)
// shallow-bind the loop variables; restore on exit
defer func(index, forloop interface{}) {
@ -127,6 +130,9 @@ func makeIterator(value interface{}) iterable {
if iter, ok := value.(iterable); ok {
return iter
}
if value == nil {
return nil
}
switch reflect.TypeOf(value).Kind() {
case reflect.Array, reflect.Slice:
return sliceWrapper(reflect.ValueOf(value))
@ -138,7 +144,7 @@ func makeIterator(value interface{}) iterable {
}
return sliceWrapper(reflect.ValueOf(array))
default:
return sliceWrapper(reflect.ValueOf([]int{}))
return nil
}
}