]> Cypherpunks repositories - gostls13.git/commit
text/template: fix truth handling of typed interface nils in if and with
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 10 Mar 2019 21:43:45 +0000 (21:43 +0000)
committerRob Pike <r@golang.org>
Tue, 14 May 2019 00:50:42 +0000 (00:50 +0000)
commit45d74aad539c645d4e50a405f55ca46811dd70d6
treed761cdcf1beba9fce676e192ad745d660dffd05a
parenteebb9db0ef1a4cad2f5dd7e8b90f699a1d50bf91
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 <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
src/text/template/exec.go
src/text/template/exec_test.go