]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: track continue nodes correctly when escaping
authorcuishuang <imcusg@gmail.com>
Fri, 23 Aug 2024 17:23:24 +0000 (01:23 +0800)
committerGopher Robot <gobot@golang.org>
Tue, 27 Aug 2024 17:55:55 +0000 (17:55 +0000)
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>

src/html/template/escape.go
src/html/template/escape_test.go

index 1eace16e25f586fb4172d8f720787fed2b42364e..5ab41b0ce92efe0f77a9cd99cdf461754b84e76d 100644 (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")
index 497ead8716ffedd2c98546f606805149c1e9f8ba..003060e90fb620a9274b94af5a0e4e759caeb222 100644 (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",