• Daniel Martí's avatar
    text/template: never call reflect.Zero(nil) · 618f88d8
    Daniel Martí authored
    It makes no sense to try to get the zero value of a nil type, hence the
    panic. When we have a nil type, use reflect.ValueOf(nil) instead.
    
    This was showing itself if one used a missing field on the data between
    parentheses, when the data was a nil interface:
    
    	t := template.Must(template.New("test").Parse(`{{ (.).foo }}`))
    	var v interface{}
    	t.Execute(os.Stdout, v)
    
    Resulting in:
    
    	panic: reflect: Zero(nil) [recovered]
    		panic: reflect: Zero(nil)
    
    Fixes #21171.
    
    Change-Id: Ifcc4a0c67e6df425b65bc9f82fde6fcf03828579
    Reviewed-on: https://go-review.googlesource.com/84482
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarRob Pike <r@golang.org>
    618f88d8
Name
Last commit
Last update
..
parse Loading commit data...
testdata Loading commit data...
doc.go Loading commit data...
example_test.go Loading commit data...
examplefiles_test.go Loading commit data...
examplefunc_test.go Loading commit data...
exec.go Loading commit data...
exec_test.go Loading commit data...
funcs.go Loading commit data...
helper.go Loading commit data...
multi_test.go Loading commit data...
option.go Loading commit data...
template.go Loading commit data...