]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: add test for HTMLEscape
authorShawn Smith <shawn.p.smith@gmail.com>
Wed, 18 Dec 2013 18:18:35 +0000 (10:18 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 18 Dec 2013 18:18:35 +0000 (10:18 -0800)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/38220044

src/pkg/encoding/json/encode_test.go

index 9395db7cb6fd543bae8e340ed59c4f77e726bebb..c4a199a1bd9a43a2ba947561d399f3fd436c1ad1 100644 (file)
@@ -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":"<html>foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `</html>"}`
+       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())
+       }
+}