From 80cedf3e8f912d7d7defd8e0495c6fd67d229555 Mon Sep 17 00:00:00 2001 From: Didier Spezia Date: Fri, 1 May 2015 18:20:31 +0000 Subject: text/template: detect unmatched else at parsing time An unmatched {{else}} should trigger a parsing error. The top level parser is able to issue an error in case of unmatched {{end}}. It does it a posteriori (i.e. after having parsed the action). Extend this behavior to also check for unmatched {{else}} Fixes #10611 Change-Id: I1d4f433cc64e11bea5f4d61419ccc707ac01bb1d Reviewed-on: https://go-review.googlesource.com/9620 Reviewed-by: Rob Pike --- src/text/template/parse/parse.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/text/template/parse/parse.go') diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go index af33880c15..d0efcbf609 100644 --- a/src/text/template/parse/parse.go +++ b/src/text/template/parse/parse.go @@ -288,11 +288,12 @@ func (t *Tree) parse(treeSet map[string]*Tree) (next Node) { } t.backup2(delim) } - n := t.textOrAction() - if n.Type() == nodeEnd { + switch n := t.textOrAction(); n.Type() { + case nodeEnd, nodeElse: t.errorf("unexpected %s", n) + default: + t.Root.append(n) } - t.Root.append(n) } return nil } -- cgit v1.3-5-g9baa