From 45d74aad539c645d4e50a405f55ca46811dd70d6 Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Sun, 10 Mar 2019 21:43:45 +0000 Subject: text/template: fix truth handling of typed interface nils in if and with Before this commit, the two logically equivalent conditionals below would produce different output: {{ if not .NonEmptyInterfaceTypedNil }}OK{{ else }}{{ end }} {{ if .NonEmptyInterfaceTypedNil }}{{ else }}OK{{ end }} The functions `not`, `or`, and `and` all use the same `truth` function, which unwraps any concrete interface value before passing it to `isTrue`. `if` and `with` also use `isTrue` to establish truth, but was missing the interface indirect call. Fixes #30501 Change-Id: I9c49eed41e737d8f162e39bef1c3b82fd5518fed GitHub-Last-Rev: 95fc2c82f26d24a457de4deaa7e5756718fbf07c GitHub-Pull-Request: golang/go#30534 Reviewed-on: https://go-review.googlesource.com/c/go/+/164958 Reviewed-by: Russ Cox Run-TryBot: Russ Cox --- src/text/template/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/text/template/exec.go') diff --git a/src/text/template/exec.go b/src/text/template/exec.go index 0e2ab0e211..4db63bfa09 100644 --- a/src/text/template/exec.go +++ b/src/text/template/exec.go @@ -285,7 +285,7 @@ func (s *state) walk(dot reflect.Value, node parse.Node) { func (s *state) walkIfOrWith(typ parse.NodeType, dot reflect.Value, pipe *parse.PipeNode, list, elseList *parse.ListNode) { defer s.pop(s.mark()) val := s.evalPipeline(dot, pipe) - truth, ok := isTrue(val) + truth, ok := isTrue(indirectInterface(val)) if !ok { s.errorf("if/with can't use %v", val) } -- cgit v1.3-5-g9baa