summaryrefslogtreecommitdiff
path: root/src/pkg/template
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2010-03-19 09:46:39 +1100
committerAndrew Gerrand <adg@golang.org>2010-03-19 09:46:39 +1100
commitb5a05d2599991aec36f779e8f4883efe46fd4767 (patch)
tree8f63d49a5589549e80982ef31b3b267f650f1737 /src/pkg/template
parent5e4165162d60519af6de7c6a63d5e0fa8595926b (diff)
downloadgolang-b5a05d2599991aec36f779e8f4883efe46fd4767.tar.gz
template: fixed html formatter bug where it would turn a []byte
into a string of decimal numbers. R=r, rsc CC=golang-dev http://codereview.appspot.com/624041
Diffstat (limited to 'src/pkg/template')
-rw-r--r--src/pkg/template/format.go10
-rw-r--r--src/pkg/template/template_test.go11
2 files changed, 18 insertions, 3 deletions
diff --git a/src/pkg/template/format.go b/src/pkg/template/format.go
index 717dcbdbb..8a31de970 100644
--- a/src/pkg/template/format.go
+++ b/src/pkg/template/format.go
@@ -61,7 +61,11 @@ func HTMLEscape(w io.Writer, s []byte) {
// HTMLFormatter formats arbitrary values for HTML
func HTMLFormatter(w io.Writer, value interface{}, format string) {
- var b bytes.Buffer
- fmt.Fprint(&b, value)
- HTMLEscape(w, b.Bytes())
+ b, ok := value.([]byte)
+ if !ok {
+ var buf bytes.Buffer
+ fmt.Fprint(&buf, value)
+ b = buf.Bytes()
+ }
+ HTMLEscape(w, b)
}
diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go
index aaf7f2ec3..2dd646807 100644
--- a/src/pkg/template/template_test.go
+++ b/src/pkg/template/template_test.go
@@ -565,3 +565,14 @@ func TestVarIndirection(t *testing.T) {
t.Errorf("for %q: expected %q got %q", input, expect, buf.String())
}
}
+
+func TestHTMLFormatterWithByte(t *testing.T) {
+ s := "Test string."
+ b := []byte(s)
+ var buf bytes.Buffer
+ HTMLFormatter(&buf, b, "")
+ bs := buf.String()
+ if bs != s {
+ t.Errorf("munged []byte, expected: %s got: %s", s, bs)
+ }
+}