Skip to content
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

html/template: document that it strips comments #28628

Open
magical opened this issue Nov 6, 2018 · 6 comments
Open

html/template: document that it strips comments #28628

magical opened this issue Nov 6, 2018 · 6 comments
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@magical
Copy link
Contributor

magical commented Nov 6, 2018

What version of Go are you using (go version)?

go1.11.1 (playground)

Does this issue reproduce with the latest release?

Yes.

What did you do?

package main

import (
	"fmt"
	"html/template"
	"os"
)

const templateSrc = `<style>/* one */</style> /* two */ <!-- three -->`

func main() {
	fmt.Println(templateSrc)
	tmpl := template.Must(template.New("").Parse(templateSrc))
	fmt.Println(tmpl.Tree.Root.String())
	tmpl.Execute(os.Stdout, nil)
}

https://play.golang.org/p/WPnEwLYTBkF

What did you expect to see?

Comments preserved in output.

<style>/* one */</style> /* two */ <!-- three -->
<style>/* one */</style> /* two */ <!-- three -->
<style>/* one */</style> /* two */ <!-- three -->

What did you see instead?

Comments are stripped.

<style>/* one */</style> /* two */ <!-- three -->
<style>/* one */</style> /* two */ <!-- three -->
<style> </style> /* two */ 

This behaviour is apparently intentional (#14256), but it is surprising and undocumented. Templates already have their own special comment syntax ({{/* */}}), so i didn't expect that they would gobble up HTML and CSS (and presumably JS) comments as well. This needs to be called out in the documentation, ideally with a rationale and workaround.

@agnivade agnivade added this to the Unplanned milestone Nov 7, 2018
@ALTree ALTree added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 7, 2018
@hellozee
Copy link
Contributor

If no one is on it, I would like to give it a try

@agnivade
Copy link
Contributor

Go for it.

@gopherbot
Copy link

Change https://golang.org/cl/148833 mentions this issue: html/template: document that comments are stripped from html templates

@empijei
Copy link
Contributor

empijei commented Mar 20, 2019

I see this has been silent for a while, @hellozee do you have time to address the comments in cl/148833 ?😊

@hellozee
Copy link
Contributor

I did update the patch accordingly, @empijei, please do drop anything that I may have missed, 😄

@jbpratt
Copy link

jbpratt commented May 12, 2019

It seems this has been quiet. Reminder for @hellozee there are 3 unresolved comments on the patchset for this issue at cl/148833 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants