From: Evan Martin Date: Mon, 11 Jul 2011 14:31:08 +0000 (-0700) Subject: json: encode \r and \n in strings as e.g. "\n", not "\u000A" X-Git-Tag: weekly.2011-07-19~130 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2f69a7359159171c0fe2ddede22a1328f71bc4ef;p=gostls13.git json: encode \r and \n in strings as e.g. "\n", not "\u000A" This is allowed by the JSON spec and is shorter/easier to read. R=golang-dev, bradfitz, rsc CC=golang-dev https://golang.org/cl/4678046 --- diff --git a/src/pkg/json/encode.go b/src/pkg/json/encode.go index adc0f0f371..3e4532cee4 100644 --- a/src/pkg/json/encode.go +++ b/src/pkg/json/encode.go @@ -344,10 +344,17 @@ func (e *encodeState) string(s string) { if start < i { e.WriteString(s[start:i]) } - if b == '\\' || b == '"' { + switch b { + case '\\', '"': e.WriteByte('\\') e.WriteByte(b) - } else { + case '\n': + e.WriteByte('\\') + e.WriteByte('n') + case '\r': + e.WriteByte('\\') + e.WriteByte('r') + default: e.WriteString(`\u00`) e.WriteByte(hex[b>>4]) e.WriteByte(hex[b&0xF])