]> Cypherpunks repositories - gostls13.git/commit
text/template: check for literals in chain of terms
authorDidier Spezia <didier.06@gmail.com>
Sat, 2 May 2015 11:03:35 +0000 (11:03 +0000)
committerRob Pike <r@golang.org>
Sat, 2 May 2015 18:48:56 +0000 (18:48 +0000)
commit76ace947aeaa53e4f743f0a3bc69cea17e63580a
tree77ede093898ce95483b3047c7082c2f55ec5f093
parent172f27652e4e2e8c8f6f5f22cab7aa5542d38651
text/template: check for literals in chain of terms

The current parser ignores obvious errors such as:
{{0.1.E}}
{{true.any}}
{{"hello".wrong}}
{{nil.E}}

The common problem is that a chain is built from
a literal value. It then panics at execution time.

Furthermore, a double dot triggers the same behavior:
{{..E}}

Addresses a TODO left in Tree.operand to catch these
errors at parsing time.

Note that identifiers can include a '.', and pipelines
could return an object which a field can be derived
from (like a variable), so they are excluded from the check.

Fixes #10615

Change-Id: I903706d1c17861b5a8354632c291e73c9c0bc4e1
Reviewed-on: https://go-review.googlesource.com/9621
Reviewed-by: Rob Pike <r@golang.org>
src/text/template/exec_test.go
src/text/template/parse/parse.go
src/text/template/parse/parse_test.go