From: cuishuang Date: Fri, 23 Aug 2024 17:23:24 +0000 (+0800) Subject: html/template: track continue nodes correctly when escaping X-Git-Tag: go1.24rc1~1097 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7b4ecaa902f1afad6093f6b6b2ea913505f91b7b;p=gostls13.git 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 Reviewed-by: Ian Lance Taylor Reviewed-by: Michael Pratt Reviewed-by: Zxilly Chou Run-TryBot: shuang cui TryBot-Result: Gopher Robot LUCI-TryBot-Result: Go LUCI --- diff --git a/src/html/template/escape.go b/src/html/template/escape.go index 1eace16e25..5ab41b0ce9 100644 --- a/src/html/template/escape.go +++ b/src/html/template/escape.go @@ -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") diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go index 497ead8716..003060e90f 100644 --- a/src/html/template/escape_test.go +++ b/src/html/template/escape_test.go @@ -1060,6 +1060,10 @@ func TestErrors(t *testing.T) { "{{range .Items}}{{end}}", "z:1:29: at range loop continue: {{range}} branches end in different contexts", }, + { + "{{range .Items}}{{if .X}}{{break}}{{end}}{{if .Z}}{{continue}}{{end}}{{end}}", + "z:1:54: at range loop continue: {{range}} branches end in different contexts", + }, { "