mirror of
https://github.com/golang/go.git
synced 2025-11-08 12:41:02 +00:00
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
This commit is contained in:
parent
456df7c282
commit
aec37e7cb1
2 changed files with 59 additions and 1 deletions
|
|
@ -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`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue