Index: src/pkg/encoding/json/encode.go |
=================================================================== |
--- a/src/pkg/encoding/json/encode.go |
+++ b/src/pkg/encoding/json/encode.go |
@@ -264,6 +264,13 @@ |
if ok && (v.Kind() != reflect.Ptr || !v.IsNil()) { |
b, err := m.MarshalJSON() |
if err == nil { |
+ // Ensure the JSON is properly escaped. |
+ // This could be more efficient. |
+ var buf bytes.Buffer |
r
2012/02/29 00:34:49
is it worth a call to bytes.IndexAny to avoid the
dsymonds
2012/02/29 00:53:39
It would improve this particular approach, yeah. I
rsc
2012/02/29 15:50:20
I don't want to slow things down noticeably here,
|
+ HTMLEscape(&buf, b) |
+ b = buf.Bytes() |
+ } |
+ if err == nil { |
// copy JSON into buffer, checking validity. |
err = Compact(&e.Buffer, b) |
} |