Safely format data when printing

Fixes #531
This commit is contained in:
kpcyrd 2017-04-24 19:27:50 +02:00 committed by Paul Seiffert
parent 3d84af1ae0
commit f78f8d07f6
No known key found for this signature in database
GPG Key ID: C9F76DC911D6EA29
1 changed files with 2 additions and 2 deletions

View File

@ -174,14 +174,14 @@ func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
if !f.needsQuoting(value) {
b.WriteString(value)
} else {
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, value, f.QuoteCharacter)
fmt.Fprintf(b, "%q", value)
}
case error:
errmsg := value.Error()
if !f.needsQuoting(errmsg) {
b.WriteString(errmsg)
} else {
fmt.Fprintf(b, "%s%v%s", f.QuoteCharacter, errmsg, f.QuoteCharacter)
fmt.Fprintf(b, "%q", errmsg)
}
default:
fmt.Fprint(b, value)