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

Suggestions for build-web-application-with-golang/zh/04.3.md #1159

Open
lv0senku opened this issue Feb 20, 2021 · 0 comments
Open

Suggestions for build-web-application-with-golang/zh/04.3.md #1159

lv0senku opened this issue Feb 20, 2021 · 0 comments

Comments

@lv0senku
Copy link
Contributor

lv0senku commented Feb 20, 2021

Go的html/template包默认帮你过滤了html标签,但是有时候你只想要输出这个<script>alert()</script>看起来正常的信息,该怎么处理?请使用text/template。请看下面的例子:

import "text/template"
...
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
err = t.ExecuteTemplate(out, "T", "<script>alert('you have been pwned')</script>")

改为如下代码可直接运行得到输出

import (
	"text/template"
	"os"
)
t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
t.ExecuteTemplate(os.Stdout, "T", "<script>alert('you have been pwned')</script>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant