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

Most upvoted comments

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