Skip to content

Commit

Permalink
Disable HTMLEscape in reflect JSON encoder (uber-go#704)
Browse files Browse the repository at this point in the history
Fixes uber-go#700.

Zap's custom JSON encoder does not escape HTML, so make encoding
by the reflect-based JSON encoder work the same way.
  • Loading branch information
prashantv authored Apr 29, 2019
1 parent 1607c65 commit 932547e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions zapcore/json_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func (enc *jsonEncoder) resetReflectBuf() {
if enc.reflectBuf == nil {
enc.reflectBuf = bufferpool.Get()
enc.reflectEnc = json.NewEncoder(enc.reflectBuf)

// For consistency with our custom JSON encoder.
enc.reflectEnc.SetEscapeHTML(false)
} else {
enc.reflectBuf.Reset()
}
Expand Down
4 changes: 2 additions & 2 deletions zapcore/json_encoder_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ func TestJSONEncoderObjectFields(t *testing.T) {
},
{
desc: "reflect (success)",
expected: `"k":{"loggable":"yes"}`,
expected: `"k":{"escape":"<&>","loggable":"yes"}`,
f: func(e Encoder) {
assert.NoError(t, e.AddReflected("k", map[string]string{"loggable": "yes"}), "Unexpected error JSON-serializing a map.")
assert.NoError(t, e.AddReflected("k", map[string]string{"escape": "<&>", "loggable": "yes"}), "Unexpected error JSON-serializing a map.")
},
},
{
Expand Down

0 comments on commit 932547e

Please sign in to comment.