mirror of
https://github.com/golang/go
synced 2024-11-20 10:44:41 -07:00
html/template: fix docs after API changes
R=golang-dev, r CC=golang-dev https://golang.org/cl/5528109
This commit is contained in:
parent
6454a3eb15
commit
369454d7b2
@ -31,8 +31,8 @@ Example
|
||||
|
||||
import "text/template"
|
||||
...
|
||||
t, err := (&template.Set{}).Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
|
||||
err = t.Execute(out, "T", "<script>alert('you have been pwned')</script>")
|
||||
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
|
||||
err = t.ExecuteTemplate(out, "T", "<script>alert('you have been pwned')</script>")
|
||||
|
||||
produces
|
||||
|
||||
@ -42,12 +42,12 @@ but with contextual autoescaping,
|
||||
|
||||
import "html/template"
|
||||
...
|
||||
t, err := (&template.Set{}).Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
|
||||
err = t.Execute(out, "T", "<script>alert('you have been pwned')</script>")
|
||||
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
|
||||
err = t.ExecuteTemplate(out, "T", "<script>alert('you have been pwned')</script>")
|
||||
|
||||
produces safe, escaped HTML output
|
||||
|
||||
Hello, <script>alert('you have been pwned')</script>!
|
||||
Hello, <script>alert('you have been pwned')</script>!
|
||||
|
||||
|
||||
Contexts
|
||||
@ -57,8 +57,8 @@ functions to each simple action pipeline, so given the excerpt
|
||||
|
||||
<a href="/search?q={{.}}">{{.}}</a>
|
||||
|
||||
At parse time each {{.}} is overwritten to add escaping functions as necessary,
|
||||
in this case,
|
||||
At parse time each {{.}} is overwritten to add escaping functions as necessary.
|
||||
In this case it becomes
|
||||
|
||||
<a href="/search?q={{. | urlquery}}">{{. | html}}</a>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user