go: html/template: add break and continue
https://github.com/golang/go/issues/20531 added break
and continue
to text/template
, but these keywords are not available in html/template
.
Running a simple template (https://github.com/campoy/gotalks/blob/master/go1.10/template/main.go) with html/template
fails at runtime with
panic: escaping {{continue}} is unimplemented
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 15 (12 by maintainers)
Commits related to this issue
- text/template: revert CL 66410 "add break, continue actions in ranges" The new break and continue actions do not work in html/template, and fixing them requires thinking about security issues that se... — committed to golang/go by ianlancetaylor 6 years ago
- feat: add break, continue actions in ranges This is copied verbatim from https://go-review.googlesource.com/c/go/+/66410/. The above commit was reverted due to issues with html/template (see https://... — committed to jo3-l/template by jo3-l 4 years ago
- all: add break, continue actions for loops This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to i... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
- all: add break & continue loop actions This is mostly taken from https://go-review.googlesource.com/c/go/+/66410/, with some edits to support while actions. The above commit was reverted due to issue... — committed to jo3-l/template by jo3-l 3 years ago
It sure is unfortunate that we never tested that break and continue work in html templates.
I don’t believe CL 91815 is sufficient to add them. Break and continue stop the control flow midway through a range loop iteration. The flow-sensitive analysis of HTML context assumes that the loop body runs in full. It would need to be updated to take the early stop into account. I don’t see an easy way to do that in the code. Go 1.10 was supposed to have shipped already. It seems to me far too late to add a change this subtle.
It seems like the safest course of action is to remove break and continue from both text/template and html/template for Go 1.10, and then add them back in Go 1.11, with appropriate attention spent on html/template.
Thoughts?
/cc @robpike @mikesamuel @stjj89