From aec37e7cb1d34896f65948e88465376ceca68e0c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 27 Oct 2014 18:58:25 -0400 Subject: encoding/json: encode \t as \t instead of \u0009 Shorter and easier to read form for a common character. LGTM=bradfitz R=adg, bradfitz CC=golang-codereviews, zimmski https://golang.org/cl/162340043 --- src/encoding/json/encode.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/encoding/json/encode.go') diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 9b7b9d5fd1..fca2a0980b 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -805,6 +805,9 @@ func (e *encodeState) string(s string) (int, error) { case '\r': e.WriteByte('\\') e.WriteByte('r') + case '\t': + e.WriteByte('\\') + e.WriteByte('t') default: // This encodes bytes < 0x20 except for \n and \r, // as well as <, > and &. The latter are escaped because they @@ -878,9 +881,12 @@ func (e *encodeState) stringBytes(s []byte) (int, error) { case '\r': e.WriteByte('\\') e.WriteByte('r') + case '\t': + e.WriteByte('\\') + e.WriteByte('t') default: // This encodes bytes < 0x20 except for \n and \r, - // as well as < and >. The latter are escaped because they + // as well as <, >, and &. The latter are escaped because they // can lead to security holes when user-controlled strings // are rendered into JSON and served to some browsers. e.WriteString(`\u00`) -- cgit v1.3