html/template: track continue nodes correctly when escaping

Fixes #69076

Change-Id: I1a16675c466722f44d0734e95d3c8111e33ff580
Reviewed-on: https://go-review.googlesource.com/c/go/+/607736
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Zxilly Chou <zxilly@outlook.com>
Run-TryBot: shuang cui <imcusg@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
cuishuang 2024-08-24 01:23:24 +08:00 committed by Gopher Robot
parent 994d1d4466
commit 7b4ecaa902
2 changed files with 5 additions and 1 deletions

View File

@ -145,7 +145,7 @@ func (e *escaper) escape(c context, n parse.Node) context {
return c
case *parse.ContinueNode:
c.n = n
e.rangeContext.continues = append(e.rangeContext.breaks, c)
e.rangeContext.continues = append(e.rangeContext.continues, c)
return context{state: stateDead}
case *parse.IfNode:
return e.escapeBranch(c, &n.BranchNode, "if")

View File

@ -1060,6 +1060,10 @@ func TestErrors(t *testing.T) {
"{{range .Items}}<a{{if .X}}{{continue}}{{end}}>{{end}}",
"z:1:29: at range loop continue: {{range}} branches end in different contexts",
},
{
"{{range .Items}}{{if .X}}{{break}}{{end}}<a{{if .Y}}{{continue}}{{end}}>{{if .Z}}{{continue}}{{end}}{{end}}",
"z:1:54: at range loop continue: {{range}} branches end in different contexts",
},
{
"<a b=1 c={{.H}}",
"z: ends in a non-text context: {stateAttr delimSpaceOrTagEnd",