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: unexpected behaviour when using "onclick" #34691

Closed
bakurits opened this issue Oct 4, 2019 · 4 comments
Closed

html/template: unexpected behaviour when using "onclick" #34691

bakurits opened this issue Oct 4, 2019 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@bakurits
Copy link

bakurits commented Oct 4, 2019

What did you do?

my template file looks like this
Screenshot from 2019-10-04 14-44-22

when i trying to execute it with I get extra symbols around onclick
Screenshot from 2019-10-04 14-45-40

@ianlancetaylor
Copy link
Contributor

Please show us a small self-contained Go program that demonstrates the problem. Thanks.

@ianlancetaylor ianlancetaylor changed the title html template unexpected behaviour when using "onclick" html/template: unexpected behaviour when using "onclick" Oct 4, 2019
@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 4, 2019
@kevburnsjr
Copy link

kevburnsjr commented Oct 5, 2019

@ianlancetaylor https://play.golang.org/p/T1OUlHQ4oVv

package main

import (
	"os"
	"html/template"
)

const tpl = `<a 
	id1="{{.Name}}"
	id="{{.Name}}"
	onclick="{{.Name}}"
	idonclick1="{{.Name}}"
	asd="{{.Name}}"
>bar</a>`

func main() {
	t, _ := template.New("foo").Parse(tpl)
	t.Execute(os.Stdout, struct{Name string}{"baz"})
}
<a 
	id1="baz"
	id="baz"
	onclick="&#34;baz&#34;"
	idonclick1="baz"
	asd="baz"
>bar</a>

@smasher164
Copy link
Member

I believe this is working as intended. Changing the type of Name to template.JS resolves this behavior, since it must be explicitly mentioned that the string is a trustworthy JS expression.

@bakurits bakurits closed this as completed Oct 7, 2019
@Laur1nMartins
Copy link

Damn i was having this issue for a week now and just stumbled upon this Thread! Many thanks :)

@golang golang locked and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants