Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(165)

Unified Diff: src/pkg/encoding/json/encode.go

Issue 5707054: code review 5707054: encoding/json: escape output from Marshalers. (Closed)
Patch Set: diff -r 0e8f0096e631 https://go.googlecode.com/hg/ Created 13 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/pkg/encoding/json/encode_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
}
« no previous file with comments | « no previous file | src/pkg/encoding/json/encode_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b