Skip to content

Commit fef2351

Browse files
committed
Format and remove 04.3.md spaces
1 parent ef3f50e commit fef2351

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Diff for: zh/04.3.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
我们看4.1小节的例子
1717
```Go
1818

19-
fmt.Println("username:", template.HTMLEscapeString(r.Form.Get("username"))) //输出到服务器端
20-
fmt.Println("password:", template.HTMLEscapeString(r.Form.Get("password")))
21-
template.HTMLEscape(w, []byte(r.Form.Get("username"))) //输出到客户端
19+
fmt.Println("username:", template.HTMLEscapeString(r.Form.Get("username"))) //输出到服务器端
20+
fmt.Println("password:", template.HTMLEscapeString(r.Form.Get("password")))
21+
template.HTMLEscape(w, []byte(r.Form.Get("username"))) //输出到客户端
2222
```
2323
如果我们输入的username是`<script>alert()</script>`,那么我们可以在浏览器上面看到输出如下所示:
2424

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

32-
import "text/template"
33-
...
34-
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
35-
err = t.ExecuteTemplate(out, "T", "<script>alert('you have been pwned')</script>")
32+
import "text/template"
33+
...
34+
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
35+
err = t.ExecuteTemplate(out, "T", "<script>alert('you have been pwned')</script>")
3636
```
3737
输出
3838

@@ -41,10 +41,10 @@ Go的html/template包默认帮你过滤了html标签,但是有时候你只想
4141
或者使用template.HTML类型
4242
```Go
4343

44-
import "html/template"
45-
...
46-
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
47-
err = t.ExecuteTemplate(out, "T", template.HTML("<script>alert('you have been pwned')</script>"))
44+
import "html/template"
45+
...
46+
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
47+
err = t.ExecuteTemplate(out, "T", template.HTML("<script>alert('you have been pwned')</script>"))
4848
```
4949
输出
5050

@@ -55,10 +55,10 @@ Go的html/template包默认帮你过滤了html标签,但是有时候你只想
5555
转义的例子:
5656
```Go
5757

58-
import "html/template"
59-
...
60-
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
61-
err = t.ExecuteTemplate(out, "T", "<script>alert('you have been pwned')</script>")
58+
import "html/template"
59+
...
60+
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
61+
err = t.ExecuteTemplate(out, "T", "<script>alert('you have been pwned')</script>")
6262
```
6363
转义之后的输出:
6464

0 commit comments

Comments
 (0)