From: David Symonds Date: Fri, 12 Jul 2013 04:35:55 +0000 (+1000) Subject: encoding/json: escape U+2028 and U+2029. X-Git-Tag: go1.2rc2~1069 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d754647963d41bcd96ea4d12d824f01e8c50f076;p=gostls13.git encoding/json: escape U+2028 and U+2029. Fixes #5836. R=golang-dev, bradfitz, r, rsc CC=golang-dev https://golang.org/cl/10883045 --- diff --git a/src/pkg/encoding/json/decode_test.go b/src/pkg/encoding/json/decode_test.go index 97cbb4f09b..1191d6cee5 100644 --- a/src/pkg/encoding/json/decode_test.go +++ b/src/pkg/encoding/json/decode_test.go @@ -568,14 +568,14 @@ func TestUnmarshalPtrPtr(t *testing.T) { } func TestEscape(t *testing.T) { - const input = `"foobar"` - const expected = `"\"foobar\"\u003chtml\u003e"` + const input = `"foobar"` + " [\u2028 \u2029]" + const expected = `"\"foobar\"\u003chtml\u003e [\u2028 \u2029]"` b, err := Marshal(input) if err != nil { t.Fatalf("Marshal error: %v", err) } if s := string(b); s != expected { - t.Errorf("Encoding of [%s] was [%s], want [%s]", input, s, expected) + t.Errorf("Encoding of [%s]:\n got [%s]\nwant [%s]", input, s, expected) } } diff --git a/src/pkg/encoding/json/encode.go b/src/pkg/encoding/json/encode.go index e25a9b8805..55df9b5768 100644 --- a/src/pkg/encoding/json/encode.go +++ b/src/pkg/encoding/json/encode.go @@ -149,14 +149,14 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { return buf.Bytes(), nil } -// HTMLEscape appends to dst the JSON-encoded src with <, >, and & -// characters inside string literals changed to \u003c, \u003e, \u0026 +// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029 +// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029 // so that the JSON will be safe to embed inside HTML