diff options
| author | cuishuang <imcusg@gmail.com> | 2024-08-24 01:23:24 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-08-27 17:55:55 +0000 |
| commit | 7b4ecaa902f1afad6093f6b6b2ea913505f91b7b (patch) | |
| tree | 57c74711c5c761da1ba0973af4ee7d7672006bd5 /src/html | |
| parent | 994d1d446663873dd593846a0b94147410e5922a (diff) | |
| download | go-7b4ecaa902f1afad6093f6b6b2ea913505f91b7b.tar.xz | |
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>
Diffstat (limited to 'src/html')
| -rw-r--r-- | src/html/template/escape.go | 2 | ||||
| -rw-r--r-- | src/html/template/escape_test.go | 4 |
2 files changed, 5 insertions, 1 deletions
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 @@ -1061,6 +1061,10 @@ func TestErrors(t *testing.T) { "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", }, |
