aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/exec_test.go
diff options
context:
space:
mode:
authorNodir Turakulov <nodir@google.com>2015-09-05 23:16:49 -0700
committerRob Pike <r@golang.org>2015-09-09 23:25:44 +0000
commit6599450016244b9e3e074e87d7064219ee2e5cf8 (patch)
treeaa84a8f7790fe645868195cb1d259fd6a4ec6bbc /src/text/template/exec_test.go
parent00c638d243056b24f1deeb2d1d954e62baedd468 (diff)
downloadgo-6599450016244b9e3e074e87d7064219ee2e5cf8.tar.xz
text/template: perform value validity checks
Check reflect.Value.IsValid() before calling other reflect.Value methods that panic on zero values. Added tests for cases with untyped nils. They panicked without these fixes. Removed a TODO. Fixes #12356 Change-Id: I9b5cbed26db09a0a7c36d99a93f8b9729899d51e Reviewed-on: https://go-review.googlesource.com/14340 Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/text/template/exec_test.go')
-rw-r--r--src/text/template/exec_test.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go
index 9fd01320c2..b2ed8e7938 100644
--- a/src/text/template/exec_test.go
+++ b/src/text/template/exec_test.go
@@ -337,6 +337,7 @@ var execTests = []execTest{
{"if not .BinaryFunc call", "{{ if not .BinaryFunc}}{{call .BinaryFunc `1` `2`}}{{else}}No{{end}}", "No", tVal, true},
{"Interface Call", `{{stringer .S}}`, "foozle", map[string]interface{}{"S": bytes.NewBufferString("foozle")}, true},
{".ErrFunc", "{{call .ErrFunc}}", "bla", tVal, true},
+ {"call nil", "{{call nil}}", "", tVal, false},
// Erroneous function calls (check args).
{".BinaryFuncTooFew", "{{call .BinaryFunc `1`}}", "", tVal, false},
@@ -425,12 +426,15 @@ var execTests = []execTest{
{"slice[1]", "{{index .SI 1}}", "4", tVal, true},
{"slice[HUGE]", "{{index .SI 10}}", "", tVal, false},
{"slice[WRONG]", "{{index .SI `hello`}}", "", tVal, false},
+ {"slice[nil]", "{{index .SI nil}}", "", tVal, false},
{"map[one]", "{{index .MSI `one`}}", "1", tVal, true},
{"map[two]", "{{index .MSI `two`}}", "2", tVal, true},
{"map[NO]", "{{index .MSI `XXX`}}", "0", tVal, true},
- {"map[nil]", "{{index .MSI nil}}", "0", tVal, true},
+ {"map[nil]", "{{index .MSI nil}}", "", tVal, false},
+ {"map[``]", "{{index .MSI ``}}", "0", tVal, true},
{"map[WRONG]", "{{index .MSI 10}}", "", tVal, false},
{"double index", "{{index .SMSI 1 `eleven`}}", "11", tVal, true},
+ {"nil[1]", "{{index nil 1}}", "", tVal, false},
// Len.
{"slice", "{{len .SI}}", "3", tVal, true},