forked from mirror/logrus
Quote non-string values if necessary
This commit is contained in:
parent
10e5e38b53
commit
b9cfd82645
|
@ -184,7 +184,12 @@ func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
|
|||
b.WriteString(f.quoteString(errmsg))
|
||||
}
|
||||
default:
|
||||
fmt.Fprint(b, value)
|
||||
s := fmt.Sprint(value)
|
||||
if !f.needsQuoting(s) {
|
||||
b.WriteString(s)
|
||||
} else {
|
||||
b.WriteString(f.quoteString(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func TestQuoting(t *testing.T) {
|
||||
|
@ -83,6 +84,16 @@ func TestEscaping_DefaultQuoteCharacter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEscaping_Time(t *testing.T) {
|
||||
tf := &TextFormatter{DisableColors: true}
|
||||
ts := time.Now()
|
||||
|
||||
b, _ := tf.Format(WithField("test", ts))
|
||||
if !bytes.Contains(b, []byte(fmt.Sprintf("\"%s\"", ts.Format("2006-01-02 15:04:05.999999999 -0700 MST")))) {
|
||||
t.Errorf("escaping expected for %q (result was %q)", ts, string(b))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEscaping_CustomQuoteCharacter(t *testing.T) {
|
||||
tf := &TextFormatter{DisableColors: true}
|
||||
|
||||
|
|
Loading…
Reference in New Issue