From aa20d2629284ee73637598c9635ae2f8f7530d04 Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Wed, 18 Dec 2013 10:18:35 -0800 Subject: [PATCH] encoding/json: add test for HTMLEscape R=golang-dev, rsc CC=golang-dev https://golang.org/cl/38220044 --- src/pkg/encoding/json/encode_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pkg/encoding/json/encode_test.go b/src/pkg/encoding/json/encode_test.go index 9395db7cb6f..c4a199a1bd9 100644 --- a/src/pkg/encoding/json/encode_test.go +++ b/src/pkg/encoding/json/encode_test.go @@ -425,3 +425,13 @@ func TestIssue6458(t *testing.T) { t.Errorf("Marshal(x) = %#q; want %#q", b, want) } } + +func TestHTMLEscape(t *testing.T) { + var b, want bytes.Buffer + m := `{"M":"foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `"}` + want.Write([]byte(`{"M":"\u003chtml\u003efoo \u0026\u2028 \u2029\u003c/html\u003e"}`)) + HTMLEscape(&b, []byte(m)) + if !bytes.Equal(b.Bytes(), want.Bytes()) { + t.Errorf("HTMLEscape(&b, []byte(m)) = %s; want %s", b.Bytes(), want.Bytes()) + } +}