]> Cypherpunks repositories - gostls13.git/commit
exp/template: don't panic on range of nil interface
authorGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 15 Aug 2011 03:22:28 +0000 (00:22 -0300)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 15 Aug 2011 03:22:28 +0000 (00:22 -0300)
commite3f3a5411a3f60d8ab52fb335ee4eff6eb531fd9
tree2a711d43337210c83e0d33555f1217012db5c922
parent8a439334adc7f60992e23504dcb26f01646ad5b5
exp/template: don't panic on range of nil interface

This avoids a non-obvious panic when range is used on a
nil interface, and fixes it by behaving as if the range
was empty.

The new behavior is equivalent to the outcome of iterating
on a nil map or slice, and is useful because it allows
generic structures such as used in json (map[string]interface{})
to behave correctly if a key generally set to a list or map
isn't present.

R=golang-dev, r, gustavo
CC=golang-dev
https://golang.org/cl/4876046
src/pkg/exp/template/exec.go
src/pkg/exp/template/exec_test.go