From 91fadbca17ac7e79bc60684c9f4d64c3892398e1 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 15 Aug 2011 15:15:54 -0700 Subject: [PATCH] godoc: fix escaping in templates - HTML-escape URL paths - URL-escape URL parameters R=bradfitz CC=golang-dev https://golang.org/cl/4890041 --- lib/godoc/codewalkdir.html | 7 ++++--- lib/godoc/dirlist.html | 3 ++- lib/godoc/search.html | 25 +++++++++++++------------ src/cmd/godoc/godoc.go | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/godoc/codewalkdir.html b/lib/godoc/codewalkdir.html index 6fe1a0565a..2d81d9cc4d 100644 --- a/lib/godoc/codewalkdir.html +++ b/lib/godoc/codewalkdir.html @@ -7,9 +7,10 @@ {{range .}} - - - + {{$name := html .Name}} + + + {{end}}
{{html .Name}} {{html .Title}}{{$name}} {{html .Title}}
diff --git a/lib/godoc/dirlist.html b/lib/godoc/dirlist.html index 422397e522..841e474e21 100644 --- a/lib/godoc/dirlist.html +++ b/lib/godoc/dirlist.html @@ -18,7 +18,8 @@ {{range .}} - {{.|fileInfoName|html}} + {{$name := .|fileInfoName|html}} + {{$name}} {{html .Size}} diff --git a/lib/godoc/search.html b/lib/godoc/search.html index 946160cf53..776becda2e 100644 --- a/lib/godoc/search.html +++ b/lib/godoc/search.html @@ -3,6 +3,7 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> +{{$query := urlquery .Query}} {{with .Alert}}

{{html .}} @@ -20,13 +21,13 @@ {{with .Decls}}

Package-level declarations

{{range .}} - {{$pkg := pkgLink .Pak.Path}} -

package {{html .Pak.Name}}

+ {{$pkg := pkgLink .Pak.Path | html}} +

package {{html .Pak.Name}}

{{range .Files}} - {{$src := srcLink .File.Path}} + {{$src := srcLink .File.Path | html}} {{range .Groups}} {{range .Infos}} - {{html $src}}:{{infoLine .}} + {{$src}}:{{infoLine .}} {{infoSnippet_html .}} {{end}} {{end}} @@ -36,11 +37,11 @@ {{with .Others}}

Local declarations and uses

{{range .}} - {{$pkg := pkgLink .Pak.Path}} -

package {{html .Pak.Name}}

+ {{$pkg := pkgLink .Pak.Path | html}} +

package {{html .Pak.Name}}

{{range .Files}} - {{$src := srcLink .File.Path}} - {{html $src}} + {{$src := srcLink .File.Path | html}} + {{$src}} {{range .Groups}} @@ -49,7 +50,7 @@ @@ -71,17 +72,17 @@

{{range .Infos}} - {{infoLine .}} + {{infoLine .}} {{end}}
{{range .}} - {{$src := srcLink .Filename}} + {{$src := srcLink .Filename | html}}
- {{html $src}}: + {{$src}}: {{len .Lines}} {{range .Lines}} - {{html .}} + {{html .}} {{end}} {{if not $.Complete}} ... diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 98fdc19d04..e3f8ad8d36 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -481,7 +481,7 @@ func posLink_urlFunc(node ast.Node, fset *token.FileSet) string { } var buf bytes.Buffer - buf.WriteString(http.URLEscape(relpath)) + template.HTMLEscape(&buf, []byte(relpath)) // selection ranges are of form "s=low:high" if low < high { fmt.Fprintf(&buf, "?s=%d:%d", low, high) // no need for URL escaping -- 2.48.1