diff --git a/log/json_logger.go b/log/json_logger.go index 66094b4dd..0cedbf824 100644 --- a/log/json_logger.go +++ b/log/json_logger.go @@ -31,7 +31,9 @@ func (l *jsonLogger) Log(keyvals ...interface{}) error { } merge(m, k, v) } - return json.NewEncoder(l.Writer).Encode(m) + enc := json.NewEncoder(l.Writer) + enc.SetEscapeHTML(false) + return enc.Encode(m) } func merge(dst map[string]interface{}, k, v interface{}) { diff --git a/log/json_logger_test.go b/log/json_logger_test.go index e3e309090..6432fc837 100644 --- a/log/json_logger_test.go +++ b/log/json_logger_test.go @@ -73,6 +73,18 @@ func TestJSONLoggerNilErrorValue(t *testing.T) { } } +func TestJSONLoggerNoHTMLEscape(t *testing.T) { + t.Parallel() + buf := &bytes.Buffer{} + logger := log.NewJSONLogger(buf) + if err := logger.Log("k", "<&>"); err != nil { + t.Fatal(err) + } + if want, have := `{"k":"<&>"}`+"\n", buf.String(); want != have { + t.Errorf("\nwant %#v\nhave%#v", want, have) + } +} + // aller implements json.Marshaler, encoding.TextMarshaler, and fmt.Stringer. type aller struct{}