Skip to content

Commit aa20d26

Browse files
shawnpsbradfitz
authored andcommitted
encoding/json: add test for HTMLEscape
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/38220044
1 parent 33580e8 commit aa20d26

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/pkg/encoding/json/encode_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,13 @@ func TestIssue6458(t *testing.T) {
425425
t.Errorf("Marshal(x) = %#q; want %#q", b, want)
426426
}
427427
}
428+
429+
func TestHTMLEscape(t *testing.T) {
430+
var b, want bytes.Buffer
431+
m := `{"M":"<html>foo &` + "\xe2\x80\xa8 \xe2\x80\xa9" + `</html>"}`
432+
want.Write([]byte(`{"M":"\u003chtml\u003efoo \u0026\u2028 \u2029\u003c/html\u003e"}`))
433+
HTMLEscape(&b, []byte(m))
434+
if !bytes.Equal(b.Bytes(), want.Bytes()) {
435+
t.Errorf("HTMLEscape(&b, []byte(m)) = %s; want %s", b.Bytes(), want.Bytes())
436+
}
437+
}

0 commit comments

Comments
 (0)