From: Rob Pike Date: Fri, 21 Sep 2012 19:55:11 +0000 (+1000) Subject: [release-branch.go1] effective_go: use html/template instead of text/template X-Git-Tag: go1.0.3~21 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b7f91ba06f79ec5cd278ac8e4a14c5d88130c3f6;p=gostls13.git [release-branch.go1] effective_go: use html/template instead of text/template ««« backport e3fce06291ec effective_go: use html/template instead of text/template Should have done this a long time ago. Fixes #3811. R=golang-dev, adg, rsc CC=golang-dev https://golang.org/cl/6488120 »»» --- diff --git a/doc/effective_go.html b/doc/effective_go.html index 6cacac6303..d38b781b45 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -2992,11 +2992,11 @@ server; it blocks while the server runs. executes the template on the data in the form value named s.

-The template package is powerful; +The template package html/template is powerful; this program just touches on its capabilities. -In essence, it rewrites a piece of text on the fly by substituting elements derived +In essence, it rewrites a piece of HTML text on the fly by substituting elements derived from data items passed to templ.Execute, in this case the -form value. +form value. Within the template text (templateStr), double-brace-delimited pieces denote template actions. The piece from {{html "{{if .}}"}} @@ -3005,13 +3005,14 @@ is non-empty. That is, when the string is empty, this piece of the template is suppressed.

-The snippet {{html "{{urlquery .}}"}} says to process the data with the function -urlquery, which sanitizes the query string -for safe display on the web page. +The two snippets {{html "{{.}}"}} say to show the data presented to +the template—the query string—on the web page. +The HTML template package automatically provides appropriate escaping so the +text is safe to display.

The rest of the template string is just the HTML to show when the page loads. -If this is too quick an explanation, see the documentation +If this is too quick an explanation, see the documentation for the template package for a more thorough discussion.

diff --git a/doc/progs/eff_qr.go b/doc/progs/eff_qr.go index de96a0208f..0733bb1637 100644 --- a/doc/progs/eff_qr.go +++ b/doc/progs/eff_qr.go @@ -2,9 +2,9 @@ package main import ( "flag" + "html/template" "log" "net/http" - "text/template" ) var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18 @@ -31,9 +31,9 @@ const templateStr = ` {{if .}} - +
-{{html .}} +{{.}}

{{end}}