Skip to content

html/template: document that comments are stripped from html templates #28733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/html/template/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ functions.
For these internal escaping functions, if an action pipeline evaluates to
a nil interface value, it is treated as though it were an empty string.

HTML/CSS/JS comments make the injection context ambiguous, and so correct
escaping can't be guaranteed. A possible workaround is using a template.HTML variable.
For more information you can refer to this https://github.com/golang/go/issues/28628

Errors

See the documentation of ErrorCode for details.
Expand Down
3 changes: 2 additions & 1 deletion src/html/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ func (t *Template) DefinedTemplates() string {
// Parse parses text as a template body for t.
// Named template definitions ({{define ...}} or {{block ...}} statements) in text
// define additional templates associated with t and are removed from the
// definition of t itself.
// definition of t itself. Comments in the html format i.e <!-- comment -->
// are stripped while parsing.
//
// Templates can be redefined in successive calls to Parse,
// before the first use of Execute on t or any associated template.
Expand Down