Skip to content

Commit 08bd49a

Browse files
committed
html/template: document that comments are stripped from html templates
The exsisting documentaion doesn't document that the comments are stripped from html templates after they are parsed. This patch tries to document the behavior and provide a rationale along with a workaround for that. Fixes #28628
1 parent f58b02a commit 08bd49a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/html/template/template.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ func (t *Template) DefinedTemplates() string {
173173
// Parse parses text as a template body for t.
174174
// Named template definitions ({{define ...}} or {{block ...}} statements) in text
175175
// define additional templates associated with t and are removed from the
176-
// definition of t itself.
176+
// definition of t itself. Comments in the html format i.e <!-- comment -->
177+
// are stripped while parsing, this is because they make the injection context
178+
// ambiguous, and so correct escaping can't be guaranteed. A possible workaround
179+
// is using a template.HTML variable.
177180
//
178181
// Templates can be redefined in successive calls to Parse,
179182
// before the first use of Execute on t or any associated template.

0 commit comments

Comments
 (0)