diff options
author | Mike Samuel <mikesamuel@gmail.com> | 2011-09-14 11:52:03 -0700 |
---|---|---|
committer | Mike Samuel <mikesamuel@gmail.com> | 2011-09-14 11:52:03 -0700 |
commit | 514c9243f21fb8ec1df73ac63717d10e3136afa2 (patch) | |
tree | c0ccd9374201623f5df5d13198608096e960b515 | |
parent | 7edfcede1303b498b55d261d35eb4c98901edc4b (diff) | |
download | go-514c9243f21fb8ec1df73ac63717d10e3136afa2.tar.gz go-514c9243f21fb8ec1df73ac63717d10e3136afa2.zip |
exp/template/html: check that modified nodes are not shared by templates
R=nigeltao
CC=golang-dev
https://golang.org/cl/5012044
-rw-r--r-- | src/pkg/exp/template/html/escape.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/pkg/exp/template/html/escape.go b/src/pkg/exp/template/html/escape.go index 22a5521340..3c0996c46a 100644 --- a/src/pkg/exp/template/html/escape.go +++ b/src/pkg/exp/template/html/escape.go @@ -178,6 +178,9 @@ func (e *escaper) escapeAction(c context, n *parse.ActionNode) context { default: s = append(s, "html") } + if _, ok := e.actionNodeEdits[n]; ok { + panic(fmt.Sprintf("node %s shared between templates", n)) + } e.actionNodeEdits[n] = s return c } @@ -294,7 +297,10 @@ func (e *escaper) escapeBranch(c context, n *parse.BranchNode, nodeName string) // The "true" branch of a "range" node can execute multiple times. // We check that executing n.List once results in the same context // as executing n.List twice. + ae, te := e.actionNodeEdits, e.templateNodeEdits + e.actionNodeEdits, e.templateNodeEdits = make(map[*parse.ActionNode][]string), make(map[*parse.TemplateNode]string) c0 = join(c0, e.escapeList(c0, n.List), n.Line, nodeName) + e.actionNodeEdits, e.templateNodeEdits = ae, te if c0.state == stateError { // Make clear that this is a problem on loop re-entry // since developers tend to overlook that branch when @@ -323,6 +329,9 @@ func (e *escaper) escapeList(c context, n *parse.ListNode) context { func (e *escaper) escapeTemplate(c context, n *parse.TemplateNode) context { c, name := e.escapeTree(c, n.Name, n.Line) if name != n.Name { + if _, ok := e.templateNodeEdits[n]; ok { + panic(fmt.Sprintf("node %s shared between templates", n)) + } e.templateNodeEdits[n] = name } return c |