Skip to content
Myr

refactor: replace magic number 128 with unicode.MaxASCII in AsciiJSON Render (#4224)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Name · committed by GitHub · parent bb82473 · Browse files · 1 file+2 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: huangzw <huangzw@2345.com>

Diff stats

1 file+2 added−1 removed

  • other:+2 added−1 removed

1 file+2 added−1 removed

modified:render/json.go+2 added-1 removed
7 unmodified lines
8 "bytes"9 "fmt"10 "html/template"11 "net/http"12 "unicode"1314 "github.com/gin-gonic/gin/internal/bytesconv"15 "github.com/gin-gonic/gin/internal/json"16)
145 unmodified lines
162 var buffer bytes.Buffer163 escapeBuf := make([]byte, 0, 6) // Preallocate 6 bytes for Unicode escape sequences164165 for _, r := range bytesconv.BytesToString(ret) {165 if r >= 128 {166 if r > unicode.MaxASCII {167 escapeBuf = fmt.Appendf(escapeBuf[:0], "\\u%04x", r) // Reuse escapeBuf168 buffer.Write(escapeBuf)169 } else {170 buffer.WriteByte(byte(r))
24 unmodified lines