json: Add HTMLEscape

R=rsc
CC=golang-dev
https://golang.org/cl/1496042
This commit is contained in:
Micah Stetson 2010-07-12 11:26:41 -07:00 committed by Russ Cox
parent e03a50dd11
commit b5b6ce0804
2 changed files with 47 additions and 0 deletions

View file

@ -139,6 +139,16 @@ func TestUnmarshalPtrPtr(t *testing.T) {
}
}
func TestHTMLEscape(t *testing.T) {
b, err := MarshalForHTML("foobarbaz<>&quux")
if err != nil {
t.Fatalf("MarshalForHTML error: %v", err)
}
if !bytes.Equal(b, []byte(`"foobarbaz\u003c\u003e\u0026quux"`)) {
t.Fatalf("Unexpected encoding of \"<>&\": %s", b)
}
}
func noSpace(c int) int {
if isSpace(c) {
return -1