into a string of decimal numbers.
R=r, rsc
CC=golang-dev
https://golang.org/cl/624041
// 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)
}
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)
+ }
+}