diff options
| author | Russ Cox <rsc@golang.org> | 2021-05-05 21:13:24 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2021-05-06 13:39:39 +0000 |
| commit | d2fd503f687ca686cb8fbee0b29e64ba529038fe (patch) | |
| tree | 71e62367ff1a6b5af78e6c2985f87e650d79aa7d /src/text/template/exec_test.go | |
| parent | 0e7a7a68cd2a29895eae345ce56145b780d4a06c (diff) | |
| download | go-d2fd503f687ca686cb8fbee0b29e64ba529038fe.tar.xz | |
text/template: fix type bug in eq
{{eq .x 0}} where .x is a nil interface{} should be false, not a type error.
Similarly, {{eq .x .x}} should succeed, not panic in reflect.
Fixes #45982.
Change-Id: I90aba82bb2f1a9e162bde1290c94f5028f56f412
Reviewed-on: https://go-review.googlesource.com/c/go/+/317470
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/text/template/exec_test.go')
| -rw-r--r-- | src/text/template/exec_test.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go index e73fce4fa8..ef521645a7 100644 --- a/src/text/template/exec_test.go +++ b/src/text/template/exec_test.go @@ -1201,8 +1201,11 @@ var cmpTests = []cmpTest{ {"eq .Ptr .NilPtr", "false", true}, {"eq .NilPtr .NilPtr", "true", true}, {"eq .Iface1 .Iface1", "true", true}, - {"eq .Iface1 .Iface2", "false", true}, - {"eq .Iface2 .Iface2", "true", true}, + {"eq .Iface1 .NilIface", "false", true}, + {"eq .NilIface .NilIface", "true", true}, + {"eq .NilIface .Iface1", "false", true}, + {"eq .NilIface 0", "false", true}, + {"eq 0 .NilIface", "false", true}, // Errors {"eq `xy` 1", "", false}, // Different types. {"eq 2 2.0", "", false}, // Different types. @@ -1217,12 +1220,12 @@ var cmpTests = []cmpTest{ func TestComparison(t *testing.T) { b := new(bytes.Buffer) var cmpStruct = struct { - Uthree, Ufour uint - NegOne, Three int - Ptr, NilPtr *int - Map map[int]int - V1, V2 V - Iface1, Iface2 fmt.Stringer + Uthree, Ufour uint + NegOne, Three int + Ptr, NilPtr *int + Map map[int]int + V1, V2 V + Iface1, NilIface fmt.Stringer }{ Uthree: 3, Ufour: 4, |
