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 · May be fixed by #28733

Comments

@magical
Copy link
Contributor

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 the help wanted label Nov 7, 2018
@agnivade agnivade added this to the Unplanned milestone Nov 7, 2018
@ALTree ALTree added the NeedsFix label Nov 7, 2018
@hellozee

This comment has been minimized.

Copy link
Contributor

commented Nov 12, 2018

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

@agnivade

This comment has been minimized.

Copy link
Member

commented Nov 12, 2018

Go for it.

hellozee added a commit to hellozee/go that referenced this issue Nov 12, 2018
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 golang#28628
@gopherbot

This comment has been minimized.

Copy link

commented Nov 12, 2018

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

@empijei

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Mar 21, 2019

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

@jbpratt78

This comment has been minimized.

Copy link

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
Projects
None yet
7 participants
You can’t perform that action at this time.