aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/encode.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-10-27 18:58:25 -0400
committerRuss Cox <rsc@golang.org>2014-10-27 18:58:25 -0400
commitaec37e7cb1d34896f65948e88465376ceca68e0c (patch)
tree095b4904cf74b5b78339b69576646b3c138cad43 /src/encoding/json/encode.go
parent456df7c282f984133a4e687e5cff1bcda0f180e4 (diff)
downloadgo-aec37e7cb1d34896f65948e88465376ceca68e0c.tar.xz
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
Diffstat (limited to 'src/encoding/json/encode.go')
-rw-r--r--src/encoding/json/encode.go8
1 files changed, 7 insertions, 1 deletions
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`)